Advertisement
Guest User

Untitled

a guest
Feb 9th, 2015
26
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2.  * Build Commands for WorldEdit
  3.  * Copyright (C) 2013 inHaze <http://bit.ly/inHaze>
  4.  *
  5.  * This program is free software: you can redistribute it and/or modify
  6.  * it under the terms of the GNU General Public License as published by
  7.  * the Free Software Foundation, either version 3 of the License, or
  8.  * (at your option) any later version.
  9.  *
  10.  * This program is distributed in the hope that it will be useful,
  11.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13.  * GNU General Public License for more details.
  14.  *
  15.  * You should have received a copy of the GNU General Public License
  16.  * along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18.        
  19. importPackage(Packages.java.awt.image);         //used for map images  
  20. importPackage(Packages.javax.imageio);
  21. importPackage(Packages.java.io);            //saving and reading files
  22. importPackage(Packages.org.bukkit);         //bukkit specific items
  23. importPackage(Packages.com.sk89q.worldedit);        //rest of the worldedit stuff  
  24. importPackage(Packages.com.sk89q.worldedit.blocks);
  25. importPackage(Packages.com.sk89q.worldedit.patterns);
  26. importPackage(Packages.com.sk89q.worldedit.vector);
  27. importPackage(Packages.com.sk89q.worldedit.regions);
  28. importPackage(Packages.com.sk89q.worldedit.regions.region);
  29. importPackage(Packages.com.sk89q.worldedit.tools);
  30. importPackage(Packages.com.sk89q.worldedit.tools.brushes);
  31.  
  32. var version = "1.0";
  33. var stage = 0;
  34. var invert = 1;
  35. var zVec = Vector(0,0,0);
  36. var gVec = Vector(0,0,0);
  37. var gSize = -1;
  38.  
  39. context.getSession().setTool(player.getItemInHand(), null)
  40. var tool = context.getSession().getBrushTool(player.getItemInHand());
  41. var airMat = new SingleBlockPattern(new BaseBlock(0,1));       
  42. var gMat = airMat;
  43.  
  44. tool.setSize(gSize);
  45. tool.setFill(gMat);
  46.  
  47. var offsetVec = [];
  48. var entityList = [];
  49. var oreList = [];
  50. var vecList = [];
  51. var myKit = [];
  52. var myShape = [];
  53. var tools = [];
  54. var trees = [];
  55. var shapes = [];
  56. var blocks = [];
  57. var text = [];
  58.  
  59. SetObjectGroups();
  60.  
  61. var modeArg = argv.length > 1 ? argv[1] : 2;
  62. var mode = parseMode(modeArg);      //test and return a good mode value
  63.  
  64. var brush = new Brush({     //Setup the brush - This is what runs each time it's clicked
  65.     build : function(editSession,posB,mat,size) {
  66.        
  67.         try {
  68.             var pos = checkFlag("~") ? player.getBlockTrace(parseInt(checkFlag("~")), true) : player.getBlockTrace(200, false);
  69.             if (pos == null) { return; }
  70.  
  71.             vecList.unshift(pos);
  72.            
  73.             var blackList = [6,31,32,37,38,39,30,78];   //Move the position down one if a natural block is clicked (grass, flowers, etc)
  74.             if (parseInt(blackList.indexOf(editSession.getBlock(pos).getType())) != -1) {
  75.                 pos = pos.add(0,-1,0);
  76.             }
  77.            
  78.             gMat = ((mat.next(0,0,0).getType() == 0) && (mat.next(0,0,0).getData() == 1)) ? gMat : mat;     //set gMat if brush mat has changed
  79.             gSize = size != -1 ? size : -1;
  80.             invert = pos.getY() <= player.getBlockIn().getY() ? 1 : -1;
  81.            
  82.             tools[mode].mySub(pos, editSession);        //run the function for the specified mode
  83.            
  84.             if(editSession.getBlock(player.getBlockIn().add(0,1,0)).getType() != 0) {       //if player has been covered, find free spot
  85.                 player.findFreePosition();
  86.             }
  87.         }
  88.         catch (e)   {
  89.             //player.print(text.Red + "Error! " + text.White + String(e));
  90.             if ((String(e)) != "ReferenceError: \"aError\" is not defined.")    {
  91.                 player.print(text.Red + "Error! " + text.White + String(e));
  92.             }
  93.         }
  94.     },
  95.    
  96. });
  97.  
  98. if (argv.length < 2)  {
  99.     HelpText(0);
  100. }
  101. else {
  102.     InitializeBrush();
  103. }
  104.  
  105. //////////////////////////////////////////////////////////
  106. //              Internal Utility Functions
  107. //////////////////////////////////////////////////////////
  108.  
  109. function SetObjectGroups()  {
  110.  
  111.     oreList = {
  112.         '1':  {BlockID:  16,            //Coal Ore
  113.             chance:   100,          //Weighted probability, coal ore is considered baseline at 100, use 0 to stop an item from spawning completely
  114.             minSize:   8,           //minimum possible vein size
  115.             maxSize:    16,         //maximum possible vein size
  116.             minY:   0,              //Lowest possible spawning y height
  117.             maxY:   256             //Highest possible spawning y height
  118.         },
  119.         '2':  {BlockID:  15,            //Iron Ore
  120.             chance:   60,
  121.             minSize:   6,
  122.             maxSize:    12,
  123.             minY:   16,
  124.             maxY:   256
  125.         },
  126.         '3':  {BlockID:  14,            //Gold Ore
  127.             chance:   18,
  128.             minSize:   6,
  129.             maxSize:    10,
  130.             minY:   4,
  131.             maxY:   32
  132.         },
  133.         '4':  {BlockID:  56,            //Diamond Ore
  134.             chance:   16,
  135.             minSize:   4,
  136.             maxSize:    8,
  137.             minY:   0,
  138.             maxY:   16 
  139.         },
  140.         '5':  {BlockID:  21,            //Lapis Lazuli Ore
  141.             chance:   14,
  142.             minSize:   4,
  143.             maxSize:    10,
  144.             minY:   0,
  145.             maxY:   32
  146.         },
  147.         '6':  {BlockID:  73,            //Redstone Ore
  148.             chance:   75,
  149.             minSize:   6,
  150.             maxSize:    10,
  151.             minY:   0,
  152.             maxY:   15
  153.         },
  154.         '7':  {BlockID:  129,           //Emerald Ore
  155.             chance:   .25,
  156.             minSize:   2,
  157.             maxSize:    45,
  158.             minY:   0,
  159.             maxY:   125
  160.         },
  161.         '8':  {BlockID:  12,            //Sand
  162.             chance:   5,
  163.             minSize:   6,
  164.             maxSize:    20,
  165.             minY:   65,
  166.             maxY:   130
  167.         },
  168.         '9':  {BlockID:  13,            //Gravel
  169.             chance:   5,
  170.             minSize:   6,
  171.             maxSize:    16,
  172.             minY:   25,
  173.             maxY:   90
  174.         },
  175.         '10':  {BlockID:  82,           //Clay
  176.             chance:   5,
  177.             minSize:   4,
  178.             maxSize:    12,
  179.             minY:   50,
  180.             maxY:   110
  181.         },
  182.         '11':  {BlockID:  3,            //Dirt
  183.             chance:   5,
  184.             minSize:   4,
  185.             maxSize:    12,
  186.             minY:   60,
  187.             maxY:   175
  188.         },
  189.         '12':  {BlockID:  45,           //Bricks - Test Item
  190.             chance:   0,
  191.             minSize:   10,
  192.             maxSize:    150,
  193.             minY:   50,
  194.             maxY:   60
  195.         }
  196.     };
  197.  
  198.     trees = {
  199.         'bush':  {
  200.             woodBlock:  new BaseBlock(BlockID.LOG),        
  201.             leafBlock:   new BaseBlock(BlockID.LEAVES, 4),         
  202.             minSize:   6,
  203.             maxChg: 0,
  204.             leafSize: 5,
  205.             mySub:  CreateBush
  206.         },
  207.         'small':  {
  208.             woodBlock:  new BaseBlock(BlockID.LOG),        
  209.             leafBlock:   new BaseBlock(BlockID.LEAVES, 4),         
  210.             minSize:   6,
  211.             maxChg: 0,
  212.             leafSize: 5,
  213.             mySub:  CreateSmallTree
  214.         },
  215.         'medium':  {
  216.             woodBlock:  new BaseBlock(BlockID.LOG),        
  217.             leafBlock:   new BaseBlock(BlockID.LEAVES, 4),         
  218.             minSize:  5,
  219.             maxChg: 8,
  220.             branchSize: .5,
  221.             leafSize:   7,
  222.             mySub:  CreateMediumTree
  223.         },
  224.         'large':  {
  225.             woodBlock:  new BaseBlock(BlockID.LOG),        
  226.             leafBlock:   new BaseBlock(BlockID.LEAVES, 4),         
  227.             minSize:  20,
  228.             maxChg: 8,
  229.             branchSize: .1,
  230.             branchProb: .5,
  231.             leafSize:   7,
  232.             mySub:  CreateLargeTree
  233.         },
  234.         'branched':  {
  235.             woodBlock:  new BaseBlock(BlockID.LOG),        
  236.             leafBlock:   new BaseBlock(BlockID.LEAVES, 4),         
  237.             minSize:  25,
  238.             maxChg: 1,
  239.             branchSize1:    .3,
  240.             branchSize2:    .15,
  241.             branchSize3:    .1,
  242.             branchProb1:    .7,
  243.             branchProb2:    .7,
  244.             branchProb3:    .7,
  245.             leafSize:   13,
  246.             mySub:  CreateBranchedTree
  247.         },         
  248.         'rainforest':  {
  249.             woodBlock:  new BaseBlock(BlockID.LOG, 3),         
  250.             leafBlock:   new BaseBlock(BlockID.LEAVES, 7),         
  251.             minSize:  20,
  252.             maxChg: 8,
  253.             branchSize: .15,
  254.             branchProb: .6,
  255.             branchHeight: .6,
  256.             leafSize:   12,
  257.             mySub:  CreateRainforestTree
  258.         },
  259.         'palm':  {
  260.             woodBlock:  new BaseBlock(BlockID.LOG),        
  261.             leafBlock:   new BaseBlock(BlockID.LEAVES, 4),         
  262.             minSize:  5,
  263.             maxChg: 4,
  264.             branchSize: .5,
  265.             leafSize:   3,
  266.             mySub:  CreatePalmTree
  267.         },
  268.         'stick':  {
  269.             woodBlock:  new BaseBlock(BlockID.LOG, 0),
  270.             leafBlock:   new BaseBlock(BlockID.LEAVES, 4),             
  271.             minSize:  1,
  272.             density:    .1,
  273.             maxChg: 3,
  274.             mySub:  CreateStickTree
  275.         },
  276.         'mushroom':  {
  277.             woodBlock:  new BaseBlock(35, 4),          
  278.             leafBlock:   new BaseBlock(35, 14),        
  279.             minSize:  15,
  280.             maxChg: 40,
  281.             leafSize:   25,
  282.             mySub:  CreateMushroom
  283.         },
  284.         'spike':  {
  285.             woodBlock:  new BaseBlock(BlockID.LOG),        
  286.             leafBlock:   new BaseBlock(BlockID.LEAVES, 4),         
  287.             minSize:  25,
  288.             maxChg: 1,
  289.             branchSize1:    .3,
  290.             branchSize2:    .15,
  291.             branchSize3:    .1,
  292.             branchProb1:    .7,
  293.             branchProb2:    .7,
  294.             branchProb3:    .7,
  295.             leafSize:   13,
  296.             mySub:  CreateSpikeTree
  297.         }      
  298.     }
  299.    
  300.     shapes = {
  301.         'PalmLeaf':  {
  302.             offset: Vector(0,0,0),
  303.             angle: 0,
  304.             shape: {
  305.                 '1': {vec: Vector(0,1,0), id: "18:4"},
  306.                 '2': {vec: Vector(0,2,0), id: "18:4"},
  307.                 '3': {vec: Vector(1,1,0), id: "18:4"},
  308.                 '4': {vec: Vector(1,2,0), id: "18:4"},
  309.                 '5': {vec: Vector(2,1,0), id: "18:4"},
  310.                 '6': {vec: Vector(3,1,0), id: "18:4"},
  311.                 '7': {vec: Vector(3,0,0), id: "18:4"},
  312.                 '8': {vec: Vector(4,0,0), id: "18:4"},
  313.                 '9': {vec: Vector(4,-1,0), id: "18:4"},
  314.                 '10': {vec: Vector(1,1,-1), id: "18:4"},
  315.                 '11': {vec: Vector(1,1,1), id: "18:4"}
  316.             },
  317.         },
  318.         'Test':  {
  319.             offset: Vector(0,0,0),
  320.             angle: 0,
  321.             shape: {
  322.                 '1': {vec: Vector(0,1,0), id: "18:4"},
  323.                 '2': {vec: Vector(0,2,0), id: "18:4"},
  324.                 '3': {vec: Vector(1,1,0), id: "18:4"},
  325.                 '4': {vec: Vector(1,2,0), id: "18:4"},
  326.                 '5': {vec: Vector(2,1,0), id: "18:4"},
  327.                 '6': {vec: Vector(3,1,0), id: "18:4"},
  328.                 '7': {vec: Vector(3,0,0), id: "18:4"},
  329.                 '8': {vec: Vector(4,0,0), id: "18:4"},
  330.                 '9': {vec: Vector(4,-1,0), id: "18:4"},
  331.                 '10': {vec: Vector(1,1,-1), id: "18:4"},
  332.                 '11': {vec: Vector(1,1,1), id: "18:4"},
  333.                 '12': {vec: Vector(2,2,0), id: "5:1"},
  334.                 '13': {vec: Vector(4,1,0), id: "5:1"},
  335.                 '14': {vec: Vector(3,2,0), id: "50:1"},
  336.                 '15': {vec: Vector(5,1,0), id: "50:1"}
  337.             },
  338.         }      
  339.  
  340.     }
  341.  
  342.     blocks = {
  343.         'plants':   {
  344.             list:   {
  345.                     '0':  {block: new BaseBlock(31, 1), chance: 100, },
  346.                     '1':  {block: new BaseBlock(31, 2), chance: 100, },
  347.                     '2':  {block: new BaseBlock(37, 0), chance: 5, },
  348.                     '3':  {block: new BaseBlock(38, 0), chance: 5, },
  349.                     '4':  {block: new BaseBlock(86, 0), chance: .2, },
  350.                     '5':  {block: new BaseBlock(103, 0), chance: .2,}
  351.             }
  352.         },
  353.         'ruin': {
  354.             list:   {
  355.                     '0':  {block: new BaseBlock(98, 0), chance: 100, },
  356.                     '1':  {block: new BaseBlock(98, 1), chance: 100, },
  357.                     '2':  {block: new BaseBlock(98, 2), chance: 100, },
  358.                     '3':  {block: new BaseBlock(98, 3), chance: 5, },
  359.                     '4':  {block: new BaseBlock(109, 0), chance: 10, },
  360.                     '5':  {block: new BaseBlock(109, 4), chance: 10, },
  361.                     '6':  {block: new BaseBlock(44, 5), chance: 5,},
  362.                     '7':  {block: new BaseBlock(44, 13), chance: 5,},
  363.                     '8':  {block: new BaseBlock(97, 2), chance: 1,}
  364.             }
  365.         }      
  366.     }
  367.    
  368.     text = {
  369.         'Black': "\u00A70",
  370.         'DarkBlue': "\u00A71",
  371.         'DarkGreen': "\u00A72",
  372.         'DarkAqua': "\u00A73",
  373.         'DarkRed': "\u00A74",
  374.         'Purple': "\u00A75",
  375.         'Gold': "\u00A76",
  376.         'Grey': "\u00A77",
  377.         'DarkGrey': "\u00A78",
  378.         'Indigo': "\u00A79",
  379.         'BrightGreen': "\u00A7a",
  380.         'Aqua': "\u00A7b",
  381.         'Red': "\u00A7c",
  382.         'Pink': "\u00A7d",
  383.         'Yellow': "\u00A7e",
  384.         'White': "\u00A7f",
  385.         'Random': "\u00A7k",
  386.         'Bold': "\u00A7l",
  387.         'Strike': "\u00A7m",
  388.         'Underline': "\u00A7n",
  389.         'Italics': "\u00A7o",      
  390.         'Reset': "\u00A7r",
  391.         'Not': "\u00AC",
  392.         'Bar': "\u007C",
  393.         'Arrow': "\u00BB",
  394.     }
  395.    
  396.     tools = {
  397.         '0':  {name:  "Help",          
  398.             note:  "General, or command specific info.",           
  399.             args:   ["command"],
  400.             aFlags: [""],
  401.             keys:   ["help", "h", "?"],
  402.             brush:  0,
  403.             mySub:  HelpText,
  404.         },
  405.         '1':  {name:  "Command List(Short)",           
  406.             note:  "List Commands - Short",        
  407.             args:  [""],
  408.             aFlags: [""],
  409.             keys:  ["list", "shortlist"],
  410.             brush:  0,
  411.             mySub:  CommandListShort,
  412.         },
  413.         '2':  {name:  "Command List(Long)",        
  414.             note:  "List Commands - Long",         
  415.             args:  [""],
  416.             aFlags: [""],
  417.             keys:  ["commands", "command", "longlist"],
  418.             brush:  0,
  419.             mySub:  CommandList,
  420.         },
  421.         '3':  {name:  "Clear Nature",          
  422.             note:  "Destroys and clears all natural blocks.",          
  423.             args:  ["size"],
  424.             aFlags: ["s"],
  425.             keys:  ["clear", "killnature", "kill", "kn", "clearnature"],
  426.             brush:  1,
  427.             mySub:  ClearNature,
  428.         },
  429.         '4':  {name:  "Tree",          
  430.             note:  "Creates a randomly generated tree type.",          
  431.             args:   ["treeType", "size", "woodBlock", "leafBlock", "clump"],
  432.             aFlags: ["", "s", "w", "l", "c"],
  433.             keys:   ["tree"],
  434.             brush:  1,
  435.             mySub:  BuildTree,
  436.         },
  437.         '5':  {name:  "Grass Patch",           
  438.             note:  "Creates a random patch of long grass(super bonemeal!)",        
  439.             args:  ["size", "density"],
  440.             aFlags: ["s", "d"],
  441.             keys:  ["grass", "grasspatch", "bonemeal"],
  442.             brush:  1,
  443.             mySub:  BuildGrassPatch,
  444.         },
  445.         '6':  {name:  "Stick Patch",           
  446.             note:  "Creates a random patch of blocks to random custom heights.",           
  447.             args:  ["size", "block", "minLength,maxChg", "density"],
  448.             aFlags: ["s", "b", "l", "d"],
  449.             keys:  ["stickpatch", "stick"],
  450.             brush:  1,
  451.             mySub:  BuildStickPatch,
  452.         },     
  453.         '7':  {name:  "Overlay",           
  454.             note:  "Covers all natural items to custom blocks and depths.",        
  455.             args:  ["size", "topBlock,depth", "mid,depth", "end,depth", "all"],
  456.             aFlags:["s", "t", "m", "e", "a"],
  457.             keys:  ["overlay", "overlaypatch", "over"],
  458.             brush:  1,
  459.             mySub:  BuildOverlayPatch,
  460.         },         
  461.         '8':  {name:  "Spike",         
  462.             note:  "Creates a custom spike wherever clicked.",         
  463.             args:  ["baseSize", "block", "minLength,maxChg"],
  464.             aFlags:["s", "b", "l"],
  465.             keys:  ["spike", "cone"],
  466.             brush:  1,
  467.             mySub:  BuildSpike,
  468.         },
  469.         '9':  {name:  "Vine",          
  470.             note:  "Smart custom vine brush.",         
  471.             args:  ["size", "density", "length", "block", ],
  472.             aFlags:["s", "d", "l", "b"],
  473.             keys:  ["vine", "vines"],
  474.             brush:  1,
  475.             mySub:  BuildVines,
  476.         },
  477.         '10':  {name:  "Test",         
  478.             note:  "Function Testing Area",        
  479.             args:  [""],
  480.             aFlags: [""],
  481.             keys:  ["test"],
  482.             brush:  1,
  483.             mySub:  BuildTest,
  484.         },
  485.         '11':  {name:  "Save Shape",           
  486.             note:  "Save the current selection to shape file.",        
  487.             args:  ["fileName", "excludeBlock"],
  488.             aFlags: ["", "!"],
  489.             keys:  ["save"],
  490.             brush:  1,
  491.             mySub:  saveShape,
  492.         },
  493.         '12':  {name:  "Shape",        
  494.             note:  "Load a shape object from the selection, or shape file.",           
  495.             args:  ["fileName", "angleLock", "excludeID", "select"],
  496.             aFlags:["", "<", "!", "$"],
  497.             keys:  ["shape", "load"],
  498.             brush:  1,
  499.             mySub:  BuildShape,
  500.         }, 
  501.         '13':  {name:  "Line",         
  502.             note:  "Draws a custom line in single, continous, or fixed origin mode.",          
  503.             args:  ["mode", "size", "block", "extendCnt"],
  504.             aFlags: ["m", "s", "b", "e"],
  505.             keys:  ["line", "lines"],
  506.             brush:  1,
  507.             mySub:  BuildLine,
  508.         },
  509.         '14':  {name:  "Paint",        
  510.             note:  "Attempts to paint shape objects in rapidfire mode.",           
  511.             args:  ["fileName", "angleLock", "excludeID"],
  512.             aFlags:["", "<", "!"],
  513.             keys:  ["paint", "painter", "draw"],
  514.             brush:  1,
  515.             mySub:  BuildPaint,
  516.         },
  517.         '15':  {name:  "Flatten",          
  518.             note:  "Level all terrain to a custom height.",        
  519.             args:  ["size", "depth", "surfaceBlock"],
  520.             aFlags:["s", "d", "b"],
  521.             keys:  ["flatten", "flat", "level"],
  522.             brush:  1,
  523.             mySub:  BuildFlat,
  524.         }, 
  525.         '16':  {name:  "Shape Kit",        
  526.             note:  "Loads, and binds a list of custom shapes.",        
  527.             args:  ["fileName", "angleLock", "excludeID", "select"],
  528.             aFlags:["", "<", "!", "$"],
  529.             keys:  ["kit","shapekit"],
  530.             brush:  1,
  531.             mySub:  BuildShapeKit,
  532.         },
  533.         '17':  {name:  "Platform",         
  534.             note:  "Creates a custom platform, or path under your feet.",          
  535.             args:  ["size", "block"],
  536.             aFlags: ["s", "b"],
  537.             keys:  ["platform", "path"],
  538.             brush:  1,
  539.             mySub:  BuildPlatform,
  540.         },
  541.         '18':  {name:  "Mirror",           
  542.             note:  "Mirrors your current selection around a selected point.",          
  543.             args:  ["shift", "delete"],
  544.             aFlags: ["s", "d"],
  545.             keys:  ["mirror"],
  546.             brush:  1,
  547.             mySub:  BuildMirror,
  548.         },
  549.         '19':  {name:  "Biome",        
  550.             note:  "Creates a brush that paints a custom biome (multiplayer only)",        
  551.             args:  ["biome", "size"],
  552.             aFlags: ["", "#"],
  553.             keys:  ["biome"],
  554.             brush:  1,
  555.             mySub:  BuildBiome,
  556.         },
  557.         '20':  {name:  "Laser",        
  558.             note:  "Shoots a custom beam of blocks from your fingertips!",         
  559.             args:  ["size", "depth", "aboveMat", "belowMat"],
  560.             aFlags: ["s", "d", "a", "b"],
  561.             keys:  ["laser", "beam"],
  562.             brush:  1,
  563.             mySub:  BuildLaser,
  564.         },
  565.         '21':  {name:  "Revolve",          
  566.             note:  "Revolves a 2D slice selection around a center point.",         
  567.             args:  ["count", "useBlock"],
  568.             aFlags: ["c", "b"],
  569.             keys:  ["revolve"],
  570.             brush:  1,
  571.             mySub:  BuildRevolve,
  572.         },
  573.         '22':  {name:  "Rotate",           
  574.             note:  "Rotates a 3D selection to a set angle or # of increments.",        
  575.             args:  ["items/-angleInc", "resolution", "single"],
  576.             aFlags: ["i", "r", "s"],
  577.             keys:  ["rotate"],
  578.             brush:  1,
  579.             mySub:  BuildRotate,
  580.         },
  581.         '23':  {name:  "Erode",        
  582.             note:  "Erode the terrain away using a custom face setting.",          
  583.             args:  ["size", "maxFaces", "iterations"],
  584.             aFlags: ["s", "f", "i"],
  585.             keys:  ["erode"],
  586.             brush:  1,
  587.             mySub:  BuildErode,
  588.         },
  589.         '24':  {name:  "Fill",         
  590.             note:  "Fill the terrain in using a custom face setting.",         
  591.             args:  ["size", "maxFaces", "iterations"],
  592.             aFlags: ["s", "f", "i"],
  593.             keys:  ["fill"],
  594.             brush:  1,
  595.             mySub:  BuildFill,
  596.         },
  597.         '25':  {name:  "Smart Wand",           
  598.             note:  "A smarter, more user friendly selection wand.",        
  599.             args:  [""],
  600.             aFlags: [""],
  601.             keys:  ["wand"],
  602.             brush:  1,
  603.             mySub:  BuildWand,
  604.         },
  605.         '26':  {name:  "Ore Generator",        
  606.             note:  "Generates new veins of ore based on custom settings.",         
  607.             args:  ["size", "overBlock", "density", "region"],
  608.             aFlags: ["s", "b", "d", "r"],
  609.             keys:  ["ore", "ores"],
  610.             brush:  1,
  611.             mySub:  BuildOre,
  612.         },
  613.         '27':  {name:  "Fragment",         
  614.             note:  "Creates a fragmented sphere shape.",           
  615.             args:  ["size", "block", "density", "hollow"],
  616.             aFlags: ["s", "b", "d", "h"],
  617.             keys:  ["fragment", "frag"],
  618.             brush:  1,
  619.             mySub:  BuildFragment,
  620.         },
  621.         '28':  {name:  "Spawner",          
  622.             note:  "Creates an entity mob spawner. (multiplayer only)",        
  623.             args:  ["spawnerType"],
  624.             aFlags: [""],
  625.             keys:  ["spawner", "spawn"],
  626.             brush:  1,
  627.             mySub:  BuildSpawner,
  628.         },
  629.         '29':  {name:  "Kill",         
  630.             note:  "A special brush that kills entites. (Unstable!) (multiplayer only)",           
  631.             args:  ["entityType", "size"],
  632.             aFlags: ["", "s"],
  633.             keys:  ["kill", "killer"],
  634.             brush:  1,
  635.             mySub:  BuildKiller,
  636.         },
  637.         '30':  {name:  "Pattern",          
  638.             note:  "Replaces blocks with a custom predefined set.",        
  639.             args:  ["blockSet", "size"],
  640.             aFlags: ["b", "s"],
  641.             keys:  ["pattern", "pat", "replace"],
  642.             brush:  1,
  643.             mySub:  BuildPattern,
  644.         },
  645.         '31':  {name:  "Array",        
  646.             note:  "Arrays a selection up to 3 different directions.",         
  647.             args:  ["totalA", "totalB", "totalC"],
  648.             aFlags: ["a", "b", "c"],
  649.             keys:  ["array", "stack"],
  650.             brush:  1,
  651.             mySub:  BuildArray,
  652.         },
  653.         '32':  {name:  "Map",          
  654.             note:  "Saves a map of the area around you to a image file.",          
  655.             args:  ["fileName", "size", "heightMap"],
  656.             aFlags: ["", "s", "h"],
  657.             keys:  ["map"],
  658.             brush:  1,
  659.             mySub:  BuildMap,
  660.         }, 
  661.         '33':  {name:  "Flip",         
  662.             note:  "Flips the current selection around the clicked point.",        
  663.             args:  ["shift", "delete"],
  664.             aFlags: ["s", "d"],
  665.             keys:  ["flip"],
  666.             brush:  1,
  667.             mySub:  BuildFlip,
  668.         },
  669.         '34':  {name:  "Box",          
  670.             note:  "Creates a custom sized rectangle box brush.",          
  671.             args:  ["xSize", "ySize", "zSize", "hollow", "angled", "block", "insideBlock"],
  672.             aFlags: ["x", "y", "z", "h", "a", "b", "i"],
  673.             keys:  ["box", "rect", "rectangle"],
  674.             brush:  1,
  675.             mySub:  BuildBox,
  676.         },
  677.         '35':  {name:  "Ellipse",          
  678.             note:  "Creates a custom size ellipse brush",          
  679.             args:  ["xSize", "ySize", "zSize", "hollow", "angled", "block", "insideBlock"],
  680.             aFlags: ["x", "y", "z", "h", "a", "b", "i"],
  681.             keys:  ["ellipse"],
  682.             brush:  1,
  683.             mySub:  BuildEllipse,
  684.         },
  685.         '36':  {name:  "Spiral",           
  686.             note:  "Creates a custom spiral object.",          
  687.             args:  ["radius/-growth", "stretch", "count", "flip", "double"],
  688.             aFlags: ["r", "s", "c", "f", "d"],
  689.             keys:  ["spiral"],
  690.             brush:  1,
  691.             mySub:  BuildSpiral,
  692.         },
  693.         '37':  {name:  "Minesweeper",          
  694.             note:  "Play a game of Minesweeper, Minecraft style!",         
  695.             args:  ["xSize", "ySize", "mines", "wool", "cheat", "begginer/intermediate/expert", "hardcore"],
  696.             aFlags: ["x", "y", "m", "w", "c", "b/i/e", "h"],
  697.             keys:  ["minesweeper", "mine", "sweeper"],
  698.             brush:  1,
  699.             mySub:  BuildMineSweeper,
  700.         },     
  701.        
  702.     }
  703.    
  704. }
  705.  
  706. function InitializeBrush()  {
  707.  
  708.     var mySession = context.remember();
  709.  
  710.     if (mode != -1) {   //check to see if the mode exists or not
  711.        
  712.         if (checkFlag("?") != false )   {
  713.             HelpText(1);
  714.             context.getSession().setTool(player.getItemInHand(), null);
  715.             return;
  716.         }
  717.        
  718.         if (tools[mode].brush == 1) {
  719.  
  720.             var tmpStr = new Array();
  721.             var errStr = new Array();
  722.             switch (tools[mode].name)   {
  723.                 case "Save Shape":
  724.                     tmpStr = (text.White + text.Italics + "Click to specify shape origin point.");
  725.                     if (argv.length < 3)    {
  726.                         var errStr = (text.Red + "Error:" + text.White + " You need to specify a file name to save under.");
  727.                         player.print(errStr);
  728.                     }
  729.                     break;
  730.                 case "Shape":
  731.                     if ((argv.length < 3) || (String(argv[2]) == "-"))  {
  732.                         tmpStr = (text.White + text.Italics + "Click to specify selection shape origin point.");
  733.                     }
  734.                     else    {
  735.                        
  736.                         BuildShape(Vector(0,0,0), mySession)
  737.                         tool.setBrush(brush, "worldedit.brush.build");
  738.                         var errStr = "ShapeLoaded";
  739.                     }
  740.                     break;
  741.                 case "Shape Kit":
  742.                     if (argv.length < 3)    {
  743.                         var errStr = (text.Red + "Error:" + text.White + " You need to specify a .kit file name to load.");
  744.                         player.print(errStr);
  745.                     }
  746.                     else    {
  747.                         BuildShapeKit(Vector(0,0,0), mySession)
  748.                         var errStr = "ShapeKitLoaded";
  749.                     }
  750.                     break;
  751.                 case "Biome":
  752.                     if (BuildBiome((0,0,0), mySession) == false)    {return;}
  753.                     tmpStr = (text.Red + text.Italics + "Changes won't become effective until a chunk reload.");
  754.  
  755.                     break;
  756.                 case "Smart Wand":
  757.                     BuildWand(zVec, mySession);
  758.                     player.print(text.Gold + "Smart Wand" + text.White + " tool bound to " + text.Gold + ItemType.toHeldName(player.getItemInHand()) + ". " );
  759.                     return;
  760.                 default:
  761.                     tmpStr = (text.White + text.Italics + "Ready for first point.");
  762.                     break;
  763.             }
  764.            
  765.             if(errStr.length < 2)   {
  766.                 tool.setBrush(brush, "worldedit.brush.build");
  767.                 player.print(text.Gold + tools[mode].name + text.White + " brush bound to " + text.Gold + ItemType.toHeldName(player.getItemInHand()) + ". " );
  768.                 if (tmpStr.length > 0) {player.print(tmpStr);}
  769.             }
  770.         }
  771.         else{
  772.             var mySession = context.remember();
  773.             var pos = player.getBlockTrace(200);
  774.             invert = pos.getY() <= player.getBlockIn().getY() ? 1 : -1;
  775.             tools[mode].mySub(pos, mySession);
  776.         }
  777.     }
  778.     else    {
  779.         player.print(text.Red + modeArg + text.White + " mode not found. Type " + text.Gold + "/cs build list" + text.White + " for commands.");
  780.     }
  781.  
  782.  
  783. }
  784.  
  785. function loadShape(vec, session)    {
  786.  
  787.     if ((argv.length > 2) && (String(argv[2]) != "-"))  {
  788.  
  789.         var aStr = String(argv[2]).slice(String(argv[2]).length-4).toLowerCase();
  790.         type = aStr == ".bo2" ? 2 : 1;
  791.  
  792.         if (type == 1)  {       // shape file type
  793.            
  794.             var fileName = argv[2];
  795.             if (aStr == ".shp") {fileName = String(argv[2]).slice(0, String(argv[2]).length-4).toLowerCase()};
  796.  
  797.             var file = context.getSafeFile("shapes", String(fileName) + '.shp');
  798.             if(!file.exists()){
  799.                 player.print(text.Red + "Error! " + text.Gold + "Could not find shape file: " + text.White + text.Italics + file);
  800.                 return false;
  801.             }
  802.            
  803.             var tmpStr = loadFile(fileName, 1);
  804.             var tmpShape = parseShapeFile(tmpStr);
  805.             player.print(text.Gold + tmpShape['TMP'].shape.length + text.White + " blocks loaded from file: " + text.Gold + fileName + ".shp");
  806.             player.print(text.White + text.Italics + "Ready to place shape object.");
  807.            
  808.         }
  809.         else if (type == 2) {       // bo2 file type
  810.        
  811.             var fileName = argv[2];
  812.             var file = context.getSafeFile("bo2s", String(fileName));
  813.             if(!file.exists()){
  814.                 player.print(text.Red + "Error! " + text.Gold + "Could not find bo2 file: " + text.White + text.Italics + file);
  815.                 return false;
  816.             }
  817.            
  818.             var tmpStr = loadFile(fileName, 2);
  819.             var tmpShape = parseBO2File(tmpStr);
  820.             player.print(text.Gold + tmpShape['TMP'].shape.length + text.White + " blocks loaded from file: " + text.Gold + fileName);
  821.             player.print(text.White + text.Italics + "Ready to place shape object.");
  822.         }
  823.        
  824.     }
  825.     else {      //no file specified, use selection
  826.         var tmpStr = saveShape(vec, session);
  827.         var tmpShape = parseShapeFile(tmpStr);
  828.         player.print(text.Gold + tmpShape['TMP'].shape.length + text.White +" blocks loaded from current selection.");
  829.         player.print(text.White + text.Italics + "Ready to place shape object.");
  830.     }
  831.    
  832.     myShape = tmpShape;
  833.  
  834. }
  835.  
  836. function loadShapeKit(vec, session, kitList)    {
  837.  
  838.     for (inc in kitList)    {
  839.  
  840.         fStr = kitList[inc].shapeFile;
  841.         var aStr = String(fStr).slice(String(fStr).length-4).toLowerCase();
  842.         type = aStr == ".bo2" ? 2 : 1;
  843.  
  844.         if (type == 1)  {       // shape file type
  845.            
  846.             var fileName = fStr;
  847.             if (aStr == ".shp") {fileName = String(fStr).slice(0, String(fStr).length-4).toLowerCase()};
  848.            
  849.             var file = context.getSafeFile("shapes", String(fileName) + '.shp');
  850.             if(!file.exists()){
  851.                 player.print(text.Red + "Error! " + text.Gold + "Could not find shape file: " + text.White + text.Italics + file);
  852.                 continue;
  853.             }
  854.            
  855.             var tmpStr = loadFile(fileName, 1);
  856.             var tmpShape = parseShapeFile(tmpStr);
  857.             player.print(text.White + "Shape file: " + text.Gold + fileName + ".shp" + text.White + " bound to " + text.Gold + ItemType.toHeldName(kitList[inc].item));
  858.             player.giveItem(kitList[inc].item, 1);
  859.         }
  860.         else if (type == 2) {       // bo2 file type
  861.        
  862.             var fileName = fStr;
  863.             var file = context.getSafeFile("bo2s", String(fileName));
  864.             if(!file.exists()){
  865.                 player.print(text.Red + "Error! " + text.Gold + "Could not find bo2 file: " + text.White + text.Italics + file);
  866.                 continue;
  867.             }
  868.            
  869.             var tmpStr = loadFile(fileName, 2);
  870.             var tmpShape = parseBO2File(tmpStr);
  871.             player.print(text.White + "Shape file: " + text.Gold + fileName + text.White + " bound to " + text.Gold + ItemType.toHeldName(kitList[inc].item));
  872.             player.giveItem(kitList[inc].item, 1);
  873.         }
  874.        
  875.         myShape[inc] = tmpShape['TMP'];
  876.    
  877.     }
  878.     player.print(text.White + text.Italics + "Finished loading shapes!");
  879.    
  880. }
  881.  
  882. function saveShape(vec, session)    {
  883.  
  884.     if ((argv.length > 2) && (String(argv[2]) != "-"))  {
  885.         saveName = argv[2];
  886.     }
  887.     else    {
  888.         if (tools[mode].name == "Save Shape")   {
  889.             player.print(text.Red + "Error:" + text.White + " You need to specify a file name to save under.");
  890.             return false;
  891.         }
  892.     }
  893.     var ignore = checkFlag("!") ? parseBlock(checkFlag("!")) : -1;
  894.    
  895.     var world = context.getSession().getSelectionWorld();
  896.     var region = context.getSession().getSelection(world);
  897.    
  898.     var angle = (parseInt(getDirection().rightAngle)+270) % 360;
  899.     //var angleStr = "^" + String(angle) + "^";
  900.    
  901.     var mergeStr = "^" + String(angle) + "^" + "#0,0,0#|";
  902.     var blockCnt = 0;
  903.    
  904.     for (var x = 0; x < region.getWidth(); x++) {
  905.         for (var y = 0; y < region.getHeight(); y++) {
  906.             for (var z = 0; z < region.getLength(); z++) {
  907.                
  908.                 var tmpVec = region.getMinimumPoint().add(x, y, z);
  909.                 var block = session.getBlock(tmpVec);
  910.                 if (ignore != -1)   {
  911.                     if (block.getType() == ignore.getType())    {continue;}
  912.                 }
  913.                 var blockStr = String(block.getType()) + ":" + String(block.getData());
  914.                 var vecStr = String(tmpVec.getX()-vec.getX()) + "," + String(tmpVec.getY()-vec.getY()) + "," + String(tmpVec.getZ()-vec.getZ());
  915.                
  916.                 mergeStr = mergeStr + (blockStr + "@" + vecStr + "|");
  917.                 blockCnt++;
  918.             }
  919.         }
  920.     }
  921.    
  922.     mergeStr += "%";
  923.    
  924.     if (tools[mode].name == "Save Shape") {
  925.         var file = context.getSafeFile("shapes", String(saveName) + '.shp');
  926.         saveFile(saveName, mergeStr);
  927.         player.print(text.Gold + blockCnt + text.White + " blocks saved to shape file " + text.Gold + saveName + ".shp" + text.Red + " @ " + text.White + text.Italics + file);
  928.     }
  929.     else    {
  930.         return mergeStr;
  931.     }
  932.     //player.print(blockCnt + " totals blocks saved. [" + mergeStr.length + " total chars]");
  933.    
  934. }
  935.  
  936. function loadFile(fileName, type)   {
  937.    
  938.     if (type == 1)  {
  939.         var file = context.getSafeFile("shapes", String(fileName) + '.shp');
  940.     }
  941.     else if (type == 2) {
  942.         var file = context.getSafeFile("bo2s", String(fileName));
  943.     }
  944.     else if (type == 3) {
  945.         var file = context.getSafeFile("shapes", String(fileName) + '.kit');
  946.     }
  947.  
  948.     if(!file.exists()){
  949.         return 0;
  950.     }
  951.    
  952.     var buffer = new BufferedReader(new FileReader(file));
  953.     var bufStr = new Array();
  954.  
  955.     while (line = buffer.readLine()) {
  956.         bufStr = bufStr + line;
  957.         if (type == 2 || type == 3) {
  958.             bufStr = bufStr + "\n";
  959.         }
  960.     }
  961.     buffer.close();
  962.     return bufStr;
  963.  
  964. }
  965.  
  966. function saveFile(fileName, textStr)    {
  967.  
  968.     var file = context.getSafeFile("shapes", String(fileName) + '.shp');
  969.    
  970.     if(!file.exists()){
  971.         file.createNewFile();
  972.     }
  973.    
  974.     buffer = new BufferedWriter(new FileWriter(file));
  975.     buffer.write(String(textStr));
  976.     buffer.close();
  977.    
  978. }
  979.  
  980. function parseShapeFile(shapeStr)   {
  981.  
  982.     var tmpShape = new Array();
  983.    
  984.     tmpShape = {
  985.         'TMP':  {
  986.             offset: Vector(0,0,0),
  987.             shape: []
  988.                                    
  989.         }
  990.     }
  991.    
  992.         //   |17:4@25,3,-6|
  993.     var cnt = 0;
  994.     var inc = 0;
  995.     while (inc <= shapeStr.length)  {
  996.    
  997.         if (shapeStr.slice(inc+1, inc+2) == "%")    {
  998.    
  999.             break;
  1000.         }
  1001.         else if (shapeStr.slice(inc, inc+1) == "^") {
  1002.            
  1003.             var anglePos = shapeStr.indexOf("^", inc+1);
  1004.             var angleInc = anglePos+1;
  1005.             var anglePos2 = anglePos;
  1006.             tmpShape['TMP'].angle = String(shapeStr.slice(inc+1, anglePos2));
  1007.             inc = angleInc;
  1008.         }
  1009.         else if (shapeStr.slice(inc, inc+1) == "#") {
  1010.            
  1011.             var offsetPos = shapeStr.indexOf("#", inc+1);
  1012.             var offsetInc = offsetPos+1;
  1013.             var offsetPos2 = offsetPos;
  1014.             tmpShape['TMP'].offset = parseVector(String(shapeStr.slice(inc+1, offsetPos2)));
  1015.             inc = offsetInc;
  1016.         }
  1017.         else if (shapeStr.slice(inc, inc+1) == "|") {
  1018.  
  1019.             var blockPos = shapeStr.indexOf("@", inc+1);
  1020.             var blockInc = blockPos;
  1021.             var blockPos2 = blockPos;
  1022.             var block = parseBlock(String(shapeStr.slice(inc+1, blockPos2)));
  1023.                    
  1024.             var vecPos = shapeStr.indexOf("|", blockInc);
  1025.             var vecInc = vecPos+1;
  1026.             var vecPos2 = vecPos;
  1027.             var vec = parseVector(String(shapeStr.slice(blockPos+1, vecPos2)));
  1028.            
  1029.             var abc = "'" + cnt + "'";
  1030.            
  1031.             idStr = block.getType() + ":" + block.getData();
  1032.            
  1033.             tmpShape['TMP'].shape.push({vec: vec, id: idStr});
  1034.            
  1035.             inc = vecInc-1;
  1036.             cnt++;
  1037.         }
  1038.         else    {
  1039.  
  1040.             inc++;
  1041.         }
  1042.        
  1043.  
  1044.     }
  1045.     return tmpShape;
  1046. }
  1047.  
  1048. function parseBO2File(shapeStr) {
  1049.  
  1050.     var tmpShape = new Array();
  1051.    
  1052.     tmpShape = {
  1053.         'TMP':  {
  1054.             offset: Vector(0,0,0),
  1055.             angle: 0,
  1056.             shape: []
  1057.         }
  1058.     }
  1059.    
  1060.     var inc = shapeStr.indexOf("[DATA]");
  1061.  
  1062.     while (inc <= shapeStr.length)  {
  1063.         if (shapeStr.slice(inc, inc+1) == "\n") {
  1064.  
  1065.             var vecPos = shapeStr.indexOf(":", inc+1);
  1066.             if (vecPos != -1)   {
  1067.            
  1068.                 var vecInc = vecPos;
  1069.                 var vecPos2 = vecPos;
  1070.                 var vec = parseVector(String(shapeStr.slice(inc+1, vecPos2)));
  1071.                 vec = Vector(vec.getX(), vec.getZ()+1, vec.getY());
  1072.                
  1073.                 var blockPos = shapeStr.indexOf("\n", vecInc);
  1074.                 var blockInc = blockPos+1;
  1075.                 var blockPos2 = blockPos;
  1076.                
  1077.                 var block = parseBlock(String(shapeStr.slice(vecPos+1, blockPos2)));
  1078.                 var idStr = block.getType() + ":" + block.getData();
  1079.  
  1080.                 tmpShape['TMP'].shape.push({vec: vec, id: idStr});
  1081.                
  1082.                 inc = blockInc-1;
  1083.             }
  1084.             else    {
  1085.                 inc++
  1086.             }
  1087.         }
  1088.         else    {
  1089.             inc++;
  1090.         }
  1091.     }
  1092.     return tmpShape;
  1093. }
  1094.  
  1095. function parseKitFile(kitStr)   {
  1096.  
  1097.     var tmpKit = [];
  1098.     var inc = 0;
  1099.     kitStr = "\n" + kitStr + "\n";
  1100.  
  1101.     while (inc <= kitStr.length)    {
  1102.         if (kitStr.slice(inc, inc+1) == "\n")   {
  1103.  
  1104.             var shapePos = kitStr.indexOf(":", inc+1);
  1105.             if (shapePos != -1) {
  1106.                 var shapeInc = shapePos;
  1107.                 var shapePos2 = shapePos;
  1108.                 var fileStr = String(kitStr.slice(inc+1, shapePos2));
  1109.  
  1110.                 var itemPos = kitStr.indexOf("\n", shapeInc);
  1111.                 var itemInc = itemPos+1;
  1112.                 var itemPos2 = itemPos;
  1113.                
  1114.                 var itemID = parseInt(kitStr.slice(shapePos+1, itemPos2));
  1115.                 tmpKit.push ({shapeFile: fileStr, item: itemID});
  1116.  
  1117.                 inc = itemInc-1;
  1118.             }
  1119.             else    {
  1120.                 inc++
  1121.             }
  1122.         }
  1123.         else    {
  1124.             inc++;
  1125.         }
  1126.     }
  1127.     return tmpKit;
  1128. }
  1129.  
  1130. function parseBlock(blockStr)   {
  1131.    
  1132.     blockStr = blockStr.replace(".",":");
  1133.     pos = blockStr.indexOf(":");
  1134.    
  1135.     if (pos == -1)  {return new BaseBlock(parseInt(blockStr), 0);}
  1136.  
  1137.     id = blockStr.slice(0, pos);
  1138.     data = blockStr.slice(pos+1);
  1139.  
  1140.     return new BaseBlock(parseInt(id), parseInt(data));
  1141.  
  1142. }
  1143.  
  1144. function parseVector(blockStr)  {
  1145.  
  1146.     blockStr = blockStr.replace(/["'\(\)]/g, "");
  1147.     var pos = blockStr.indexOf(",", 0);
  1148.     var pos2 = blockStr.indexOf(",", pos+1);
  1149.    
  1150.     var x = parseInt(blockStr.slice(0, pos));
  1151.     var y = parseInt(blockStr.slice(pos+1, pos2));
  1152.     var z = parseInt(blockStr.slice(pos2+1));
  1153.    
  1154.     return Vector(x, y, z);
  1155. }
  1156.  
  1157. function parseBlockExtra(blockStr)  {
  1158.  
  1159.     pos = blockStr.indexOf(":");
  1160.     pos2 = blockStr.indexOf(",");
  1161.     var blockExtra = [];
  1162.  
  1163.     if ((pos != -1) && (pos2 != -1))    {
  1164.    
  1165.         blockExtra = {
  1166.             block:  new BaseBlock(parseInt(blockStr.slice(0, pos)), blockStr.slice(pos+1, pos2)),  
  1167.             extra: parseInt(blockStr.slice(pos2+1))
  1168.         }      
  1169.     }
  1170.    
  1171.     if ((pos != -1) &&  (pos2 == -1))   {
  1172.    
  1173.         blockExtra = {
  1174.             block:  new BaseBlock(parseInt(blockStr.slice(0, pos2)), blockStr.slice(pos+1)),   
  1175.             extra: 1
  1176.         }      
  1177.     }
  1178.    
  1179.     if ((pos == -1) && (pos2 == -1))    {
  1180.         blockExtra = {
  1181.             block:  new BaseBlock(parseInt(blockStr), 0),  
  1182.             extra: 1
  1183.         }
  1184.     }
  1185.    
  1186.     if ((pos == -1) && (pos2 != -1))    {
  1187.    
  1188.         blockExtra = {
  1189.             block:  new BaseBlock(parseInt(blockStr.slice(0, pos2)), 0),   
  1190.             extra: parseInt(blockStr.slice(pos2+1))
  1191.         }      
  1192.     }
  1193.    
  1194.     return blockExtra;
  1195.    
  1196. }
  1197.  
  1198. function parseMode(modeStr) {
  1199.  
  1200.     var modeVal = -1;
  1201.     modeStr = String(modeStr).toLowerCase();
  1202.    
  1203.     for (inc in tools)  {
  1204.         for (keyInc in tools[inc].keys) {
  1205.             if (modeStr == tools[inc].keys[keyInc]) {
  1206.                 modeVal = inc;
  1207.             }
  1208.         }
  1209.     }
  1210.     return modeVal;
  1211. }
  1212.  
  1213. function getRandomXZVec()   {
  1214.  
  1215.     var rngVec = new Vector;
  1216.     var rng = Math.random();
  1217.  
  1218.     switch (true)   {
  1219.         case (rng > 0 && rng < .25):
  1220.             rngVec = Vector(1,0,0);
  1221.             break;
  1222.         case (rng >= .25 && rng < .5):
  1223.             rngVec = Vector(-1,0,0);
  1224.             break;
  1225.         case (rng >= .5 && rng < .75):
  1226.             rngVec = Vector(0,0,1);
  1227.             break;
  1228.         case (rng >= .75 && rng < 1):
  1229.             rngVec = Vector(0,0,-1);
  1230.             break;
  1231.     }
  1232.  
  1233.     return rngVec;
  1234.  
  1235. }
  1236.  
  1237. function getRandomXZSide(vec)   {
  1238.  
  1239.     var rngVec = new Vector;
  1240.     var rng = Math.random();
  1241.     var rng2 = Math.random();
  1242.    
  1243.     if(vec.getX() == 0) {
  1244.         switch (true)   {
  1245.             case (rng > 0 && rng < .5):
  1246.                 rngVec = Vector(rng2,0,0);
  1247.                 break
  1248.             case (rng >= .5 && rng <= 1):
  1249.                 rngVec = Vector(-(rng2),0,0);
  1250.                 break;
  1251.            
  1252.         }
  1253.     }
  1254.     else    {
  1255.         switch (true)   {
  1256.             case (rng > 0 && rng < .5):
  1257.                 rngVec = Vector(0,0,-(rng2));
  1258.                 break;
  1259.             case (rng >= .5 && rng <= 1):
  1260.                 rngVec = Vector(0,0,rng2);
  1261.                 break;
  1262.  
  1263.         }
  1264.     }
  1265.  
  1266.     return rngVec;
  1267. }
  1268.  
  1269. function getListBlock(list) {
  1270.  
  1271.     var tmpList = new Array();
  1272.     //var tmpObj = new Object();
  1273.     var maxBlock = 0;
  1274.     var maxChance = 0;
  1275.     var totalChance = 0;
  1276.  
  1277.     for (inc in list){
  1278.    
  1279.         var tmpObj = new Object();
  1280.         tmpObj.myBlock = list[inc].block;
  1281.         tmpObj.minChance = totalChance;
  1282.         tmpObj.maxChance = totalChance + list[inc].chance;
  1283.         tmpList.push(tmpObj);
  1284.         totalChance += list[inc].chance;
  1285.     }
  1286.    
  1287.     randomProb = Math.random() * totalChance;
  1288.    
  1289.     for (var inc = 0; inc < tmpList.length; inc++)  {
  1290.         if ((randomProb >= tmpList[inc].minChance) && (randomProb <= tmpList[inc].maxChance))   {
  1291.             maxBlock = tmpList[inc].myBlock;
  1292.         }
  1293.     }
  1294.    
  1295.     var rng = Math.random();
  1296.     switch (true)   {
  1297.     case (rng > 0 && rng < .25):
  1298.         maxBlock.rotate90();
  1299.         break;
  1300.     case (rng >= .25 && rng < .5):
  1301.         maxBlock.rotate90Reverse();
  1302.         break;
  1303.     case (rng >= .5 && rng < .75):
  1304.         maxBlock.flip();
  1305.         break;
  1306.     case (rng >= .75 && rng < 1):
  1307.         break;
  1308.     }
  1309.  
  1310.     return maxBlock;
  1311.     //var bType = new BaseBlock(oreList[maxOreID].BlockID);
  1312.    
  1313. }
  1314.  
  1315. function getDistance(a, b)  {
  1316.  
  1317. var xSize = a.getX()-b.getX();
  1318. var ySize = a.getY()-b.getY();
  1319. var zSize = a.getZ()-b.getZ();
  1320. var distance = Math.sqrt((xSize*xSize)+(ySize*ySize)+(zSize*zSize));
  1321.  
  1322. return distance;
  1323. }
  1324.  
  1325. function getDistanceVec(a, b, length) {
  1326.     //get the vector that is the specified distance away from vec a heading to vec b
  1327.     var i = length * (1 / getDistance(a, b));
  1328.  
  1329.     var xi = a.getX() + ((b.getX() - a.getX()) * i);
  1330.     var yi = a.getY() + ((b.getY() - a.getY()) * i);
  1331.     var zi = a.getZ() + ((b.getZ() - a.getZ()) * i);
  1332.  
  1333.     var v = new Vector( xi, yi, zi );
  1334.     return v;
  1335. }
  1336.  
  1337. function rotateVec(origin, vec, angle)  {
  1338.    
  1339.     var s = Math.sin(angle * (Math.PI/180));
  1340.     var c = Math.cos(angle * (Math.PI/180));
  1341.    
  1342.     var dx = (vec.getX() - origin.getX()) * c - (vec.getZ() - origin.getZ()) * s;
  1343.     var dz = (vec.getX() - origin.getX()) * s + (vec.getZ() - origin.getZ()) * c;
  1344.  
  1345.     dx = Math.round(dx + origin.getX());
  1346.     dz = Math.round(dz + origin.getZ());
  1347.    
  1348.     return Vector(dx, vec.getY(), dz);
  1349. }
  1350.  
  1351. function getDirection() {      
  1352.     //returns object with multiple player direction properties
  1353.    
  1354.     var yaw = (player.getYaw()) % 360;
  1355.     if (yaw < 0)    {
  1356.         yaw += 360;
  1357.     }
  1358.    
  1359.     var dir = new Array();
  1360.     dir.pitch = player.getPitch();
  1361.     dir.yaw = yaw;
  1362.    
  1363.     switch(true)    {
  1364.  
  1365.         case ((yaw > 337.5) || (yaw <= 22.5)):
  1366.             dir.text = "South [Z+]";
  1367.             dir.vec = Vector(0,0,1);
  1368.             dir.angle = 0;
  1369.             dir.rightAngle = 0;
  1370.             break; 
  1371.         case ((yaw > 22.5) && (yaw <= 67.5)):
  1372.             dir.text = "South West [X- Z+]";
  1373.             dir.vec = Vector(-1,0,1);
  1374.             dir.angle = 45;
  1375.             dir.rightAngle = yaw < 45 ? 0 : 90;
  1376.             break;
  1377.         case ((yaw > 67.5) && (yaw <= 112.5)):
  1378.             dir.text = "West [X-]";
  1379.             dir.vec = Vector(-1,0,0);
  1380.             dir.angle = 90;
  1381.             dir.rightAngle = 90;
  1382.             break;
  1383.         case ((yaw > 112.5) && (yaw <= 157.5)):
  1384.             dir.text = "North West [X- Z-]";
  1385.             dir.vec = Vector(-1,0,-1);
  1386.             dir.angle = 135;
  1387.             dir.rightAngle = yaw < 135 ? 90 : 180;
  1388.             break;
  1389.         case ((yaw > 157.5) && (yaw <= 202.5)):
  1390.             dir.text = "North [Z-]";
  1391.             dir.vec = Vector(0,0,-1);
  1392.             dir.angle = 180;
  1393.             dir.rightAngle = 180;
  1394.             break;
  1395.         case ((yaw > 202.5) && (yaw <= 247.5)):
  1396.             dir.text = "North East [X+ Z-]";
  1397.             dir.vec = Vector(1,0,-1);
  1398.             dir.angle = 225;
  1399.             dir.rightAngle = yaw < 225 ? 180 : 270;
  1400.             break;
  1401.         case ((yaw > 247.5) && (yaw <= 292.5)):
  1402.             dir.text = "East [X+]";
  1403.             dir.vec = Vector(1,0,0);
  1404.             dir.angle = 270;
  1405.             dir.rightAngle = 270;
  1406.             break;
  1407.         case ((yaw > 292.5) && (yaw <= 337.5)):
  1408.             dir.text = "South West [X+ Z+]";
  1409.             dir.vec = Vector(1,0,1);
  1410.             dir.angle = 315;
  1411.             dir.rightAngle = yaw < 315 ? 270 : 0;
  1412.             break;
  1413.     }
  1414.    
  1415.     //player.print("Direction: " + dir.text + " [" + dir.yaw.toFixed(2) + "] [" + dir.pitch.toFixed(2) + "]" );
  1416.     return dir;
  1417.  
  1418. }
  1419.  
  1420. function generateError(){
  1421.  
  1422.     var tmp = aError;
  1423. }
  1424.  
  1425. function getWorldEdit(){
  1426.     //Thanks to Nividica @ http://forum.sk89q.com/threads/i-need-to-script-schematics.8972/
  1427.     //for figuring out how to get worlddit plugin from bukkit
  1428.    
  1429.     try {
  1430.         // Get the server singleton
  1431.         var bukkitServer = Bukkit.server;
  1432.      
  1433.         // Get the current plugin manager
  1434.         var bukkitPluginManager = bukkitServer.getPluginManager();
  1435.      
  1436.         // Get the world edit plugin
  1437.         var worldEditPlugin = bukkitPluginManager.getPlugin("WorldEdit");
  1438.      
  1439.         // Access the worldedit object
  1440.         var we = worldEditPlugin.getWorldEdit();
  1441.     }
  1442.     catch (e)   {
  1443.         player.print(text.Red + "Error: " + text.White + "This feature is only available while playing on a bukkit server.");
  1444.         return false
  1445.     }
  1446.     // Return
  1447.     return we;
  1448. }
  1449.  
  1450. function checkFlag(flag, start) {
  1451.  
  1452.     if (start == undefined) {start = 2;}
  1453.  
  1454.     for (var fInc in argv)  {
  1455.         if (fInc < start) {continue;}
  1456.         tmpStr = (String(argv[fInc]).slice(0, flag.length)).toLowerCase();
  1457.         if (tmpStr == String(flag).toLowerCase())   {
  1458.             var flagArg = String(argv[fInc]).slice(flag.length);
  1459.             if (flagArg.length > 0) {
  1460.                 return flagArg;
  1461.             }
  1462.             else{
  1463.                 return true;
  1464.             }
  1465.         }
  1466.     }
  1467.     return false;
  1468. }
  1469.  
  1470. function pauseScript(timeMs)    {
  1471.     var date = new Date();
  1472.     var curDate = null;
  1473.  
  1474.     do {curDate = new Date(); }
  1475.     while(curDate-date < timeMs);
  1476. }
  1477.  
  1478. function compressArray(original) {
  1479.  
  1480.     var compressed = [];
  1481.     var copy = original.slice(0);
  1482.  
  1483.     for (var i = 0; i < original.length; i++) {
  1484.  
  1485.         var myCount = 0;   
  1486.         for (var w = 0; w < copy.length; w++) {
  1487.             if (original[i] == copy[w]) {
  1488.                 myCount++;
  1489.                 delete copy[w];
  1490.             }
  1491.         }
  1492.  
  1493.         if (myCount > 0) {
  1494.             var a = new Object();
  1495.             a.value = original[i];
  1496.             a.count = myCount;
  1497.             compressed.push(a);
  1498.         }
  1499.     }
  1500.  
  1501.     return compressed;
  1502. };
  1503.  
  1504. function getColor(r, g, b)  {
  1505.  
  1506.     return ((r << 16) | (g << 8) | b);
  1507.  
  1508. }
  1509.  
  1510.  
  1511. //////////////////////////////////////////////////////////
  1512. //              Internal Creation Functions
  1513. //////////////////////////////////////////////////////////
  1514.  
  1515. function CreateLeafSphere(size, yLimit, density, hollow, vec, block, session)   {
  1516.     //size, ylimit, density, hollow, vec, block, session
  1517.    
  1518.     yLimit = yLimit > 0 ? size - yLimit: -(size - Math.abs(yLimit));
  1519.    
  1520.     for (var x = 0; x <= size; x++) {
  1521.         for (var y = 0; y <= size; y++) {
  1522.             for (var z = 0; z <= size; z++) {
  1523.            
  1524.             var pos = vec.add(x - size/2 + .5, y - size/2 + .5, z - size/2 +.5);
  1525.             var distance = getDistance(vec, pos);
  1526.            
  1527.             if (distance > size/2)  {continue;}
  1528.             if ((hollow != 0) && (distance <= (size/2 - hollow))) {continue;}
  1529.  
  1530.             var diff = (size/2) - ((size/2) * density);
  1531.             var pctIn = (1-((distance-((size/2) * density))/diff));
  1532.    
  1533.             if ((pctIn < Math.random()) && (density != 1))  {continue;}
  1534.                
  1535.             var adjY = (pos.getY() - (vec.getY()-(size/2)));
  1536.             if ((adjY < yLimit) || (adjY > (size) + yLimit))    {continue;}
  1537.    
  1538.             if (yLimit < 0) {
  1539.                 if (Math.abs(yLimit) > (size/2))    {
  1540.                     pos = pos.add(0,Math.abs(yLimit)-(size/2)+1,0);
  1541.                 }else   {
  1542.                     pos = pos.add(0,-(yLimit + (size/2))+1,0);
  1543.                 }
  1544.             }
  1545.             if (yLimit > 0) {
  1546.                 if (Math.abs(yLimit) > (size/2))    {
  1547.                     pos = pos.add(0,-(yLimit-(size/2)),0);
  1548.                 }else   {
  1549.                     pos = pos.add(0,((size/2) - yLimit),0);
  1550.                 }
  1551.             }
  1552.             if (yLimit == 0)    {
  1553.                 pos = pos.add(0, (size/2)+1,0);
  1554.             }
  1555.             session.setBlock(pos.add(0,-.5,0), block);
  1556.            
  1557.             }
  1558.         }
  1559.     }
  1560.  
  1561. }
  1562.  
  1563. function CreateLeafClump(size, vec, block, session) {
  1564.    
  1565.     size = Math.round(size * .5);
  1566.    
  1567.     var x = vec.getX();
  1568.     var y = vec.getY();
  1569.     var z = vec.getZ();
  1570.    
  1571.     if (invert == 1)    {
  1572.         for(var k = y; k <= y + size; k++) {
  1573.             var l = k - y;
  1574.             var i1 = size - l;
  1575.  
  1576.             for(var j1 = x - i1; j1 <= x + i1; ++j1) {
  1577.                 var k1 = j1 - x;
  1578.  
  1579.                 for(var l1 = z - i1; l1 <= z + i1; ++l1) {
  1580.                     var i2 = l1 - z;
  1581.  
  1582.                     if(Math.abs(k1) != i1 || Math.abs(i2) != i1 || Math.random() >= 0.5) {
  1583.                         var dest = new Vector(j1,k,l1);
  1584.                         session.setBlock(dest, block);
  1585.                     }
  1586.                 }
  1587.             }
  1588.         }
  1589.     }
  1590.     if (invert == -1)   {
  1591.         for(var k = y; k >= y - size; k--) {
  1592.             var l = k - y;
  1593.             var i1 = size - l;
  1594.  
  1595.             for(var j1 = x - i1; j1 <= x + i1; ++j1) {
  1596.                 var k1 = j1 - x;
  1597.  
  1598.                 for(var l1 = z - i1; l1 <= z + i1; ++l1) {
  1599.                     var i2 = l1 - z;
  1600.  
  1601.                     if(Math.abs(k1) != i1 || Math.abs(i2) != i1 || Math.random() >= 0.5) {
  1602.                         var dest = new Vector(j1,k,l1);
  1603.                         session.setBlock(dest, block);
  1604.                     }
  1605.                 }
  1606.             }
  1607.         }
  1608.     }
  1609. }
  1610.  
  1611. function CreateTrunk(size, height, vec, block, session) {
  1612.  
  1613.     for(var y = 0; y < height; y++) {
  1614.         CreateLeafSphere(size - (size*(y/height))+.5, 2*invert, 1, 0, vec.add(0,y*invert,0), block, session);
  1615.     }
  1616.    
  1617. }
  1618.  
  1619. function CreateShape(shapeObj, origin, angle, blockMat, excludeID, session) {
  1620.    
  1621.     //var excludeID = 0;
  1622.     var shape = shapeObj.shape;
  1623.     var afterBlocks = [];
  1624.     var minVec = zVec;
  1625.    
  1626.     //blacklist are all 'attached' block dependent items that need to be set after everything else
  1627.     var blackList = [6,26,27,28,31,37,38,39,40,50,51,54,55,59,63,64,65,66,68,69,70,71,72,75,76,77,78,81,83,93,94,96,104,105,106,111,115,127,131,132,141,142,143];
  1628.     var flipList = [44,53,67,108,109,114,126,128,134,135,136];
  1629.    
  1630.     origin = origin.add(shapeObj.offset);
  1631.     for (property in shape){
  1632.        
  1633.         if (angle == 361)   {       //this is used to make 4 copies at each 90 degree increment
  1634.             for (var ang = 0; ang < 360; ang++) {
  1635.                
  1636.                 if (blockMat.next(0,0,0).getType() < 1) {
  1637.                     var block = parseBlock(shape[property].id);
  1638.                 }
  1639.                 else    {
  1640.                     var block = blockMat.next(0,0,0);
  1641.                     block = parseBlock(shape[property].id).getType() == 0 ? parseBlock(shape[property].id) : block;
  1642.                 }
  1643.                 if (block.getType() == excludeID)   {continue;}
  1644.                 var ang = ((ang + parseInt(shapeObj.angle)) % 360);
  1645.                 switch (ang)    {
  1646.                
  1647.                     case 0:
  1648.                         vec = origin.add(-shape[property].vec.getZ(),shape[property].vec.getY()*invert,shape[property].vec.getX());
  1649.                         block.rotate90();
  1650.                         break;
  1651.                     case 90:
  1652.                         vec = origin.add(-shape[property].vec.getX(),shape[property].vec.getY()*invert,-shape[property].vec.getZ());
  1653.                         block.rotate90();
  1654.                         block.rotate90();
  1655.                         break;
  1656.                     case 180:
  1657.                         vec = origin.add(shape[property].vec.getZ(),shape[property].vec.getY()*invert,-shape[property].vec.getX());
  1658.                         block.rotate90();
  1659.                         block.rotate90();
  1660.                         block.rotate90();
  1661.                         break;
  1662.                     case 270:
  1663.                         vec = origin.add(shape[property].vec.getX(),shape[property].vec.getY()*invert,shape[property].vec.getZ());                 
  1664.                         break;
  1665.                     default:
  1666.                         vec = origin;
  1667.                         break;
  1668.                 }
  1669.                
  1670.                
  1671.                 if (invert == -1)   {
  1672.                     if (flipList.indexOf(block.getType()) != -1)    {
  1673.                         block.flip(CuboidClipboard.FlipDirection.UP_DOWN);
  1674.                     }  
  1675.                 }  
  1676.                
  1677.                 if (blackList.indexOf(block.getType()) != -1)   {
  1678.                     var tmpObj = new Object();
  1679.                     tmpObj.vec = vec;
  1680.                     tmpObj.block = block;
  1681.                
  1682.                     afterBlocks.push(tmpObj);
  1683.                 }
  1684.                 else    {
  1685.                     session.setBlock(vec, block);
  1686.                 }
  1687.             }
  1688.         }
  1689.         else {      //this is used for all normals rotation copies
  1690.  
  1691.             var endAngle = (parseInt(angle) + parseInt(shapeObj.angle)) % 360;
  1692.            
  1693.             if((shapeObj.angle == 0) || (shapeObj.angle == 180))    {
  1694.                 endAngle = (endAngle + 180) % 360;
  1695.             }
  1696.            
  1697.             if (blockMat.next(0,0,0).getType() < 1) {
  1698.                 var block = parseBlock(shape[property].id);
  1699.             }
  1700.             else    {
  1701.                 var block = blockMat.next(0,0,0);
  1702.                 block = parseBlock(shape[property].id).getType() == 0 ? parseBlock(shape[property].id) : block;
  1703.             }
  1704.             if (block.getType() == excludeID)   {continue;}
  1705.            
  1706.             switch (endAngle)   {
  1707.                 case 0:
  1708.                     vec = origin.add(-shape[property].vec.getZ(),shape[property].vec.getY()*invert,shape[property].vec.getX());
  1709.                     block.rotate90();
  1710.                     break;
  1711.                 case 90:
  1712.                     vec = origin.add(-shape[property].vec.getX(),shape[property].vec.getY()*invert,-shape[property].vec.getZ());
  1713.                     block.rotate90();
  1714.                     block.rotate90();
  1715.                     break;
  1716.                 case 180:
  1717.                     vec = origin.add(shape[property].vec.getZ(),shape[property].vec.getY()*invert,-shape[property].vec.getX());
  1718.                     block.rotate90();
  1719.                     block.rotate90();
  1720.                     block.rotate90();
  1721.                     break;
  1722.                 case 270:
  1723.                     vec = origin.add(shape[property].vec.getX(),shape[property].vec.getY()*invert,shape[property].vec.getZ());
  1724.                     break; 
  1725.                 default:
  1726.                     vec = origin.add(shape[property].vec.getX(),shape[property].vec.getY()*invert,shape[property].vec.getZ());
  1727.                     vec = rotateVec(origin, vec, (angle-shapeObj.angle+270)%360);
  1728.                     break;
  1729.             }
  1730.            
  1731.             if(minVec == zVec)  {minVec = vec;}
  1732.            
  1733.             if (invert == -1)   {
  1734.                 if (flipList.indexOf(block.getType()) != -1)    {
  1735.                     block.flip(CuboidClipboard.FlipDirection.UP_DOWN);
  1736.                 }  
  1737.             }  
  1738.            
  1739.             if (vec != origin)  {
  1740.                 if (blackList.indexOf(block.getType()) != -1)   {
  1741.                     var tmpObj = new Object();
  1742.                     tmpObj.vec = vec;
  1743.                     tmpObj.block = block;
  1744.                
  1745.                     afterBlocks.push(tmpObj);
  1746.                 }
  1747.                 else    {
  1748.                     session.setBlock(vec, block);
  1749.                 }
  1750.             }
  1751.         }
  1752.     }
  1753.    
  1754.     for (inc in afterBlocks){
  1755.         session.setBlock(afterBlocks[inc].vec, afterBlocks[inc].block);
  1756.     }
  1757.    
  1758.     if (checkFlag("$")) {
  1759.         var selector = context.getSession().getRegionSelector(player.getWorld());
  1760.         if (selector.selectPrimary(minVec)) {
  1761.             context.getSession().dispatchCUISelection(player);
  1762.         }
  1763.         if (selector.selectSecondary(vec)) {
  1764.             context.getSession().dispatchCUISelection(player);
  1765.         }
  1766.     }
  1767.  
  1768. }
  1769.  
  1770. function CreateLine(a, b, block, session)   {
  1771.  
  1772.     var distance = getDistance(a, b);
  1773.     var step = .9/distance;
  1774.  
  1775.     for( var i = 0; i <= 1; i += step) {
  1776.            
  1777.         var xi = a.getX() + ((b.getX() - a.getX()) * i);
  1778.         var yi = a.getY() + ((b.getY() - a.getY()) * i);
  1779.         var zi = a.getZ() + ((b.getZ() - a.getZ()) * i);
  1780.        
  1781.         var vec = new Vector(xi, yi, zi);
  1782.         session.setBlock(vec, block);  
  1783.     }
  1784. }
  1785.  
  1786. function CreateSpike(origin, end, block, session, size) {
  1787.  
  1788.     for (var x = 0; x <= size; x++) {
  1789.         for (var y = 0; y <= size; y++) {
  1790.             for (var z = 0; z <= size; z++) {
  1791.            
  1792.                 pos = origin.add(x - size/2, y - size/2, z - size/2);
  1793.                 distance = getDistance(origin, pos);
  1794.  
  1795.                 if (distance > size/2)  {continue;}
  1796.                 CreateLine(pos, end, block, session);
  1797.             }
  1798.         }
  1799.     }
  1800.  
  1801. }
  1802.  
  1803. function CreateSphere(size, hollow, vec, block, session)    {
  1804.     //hollow = the number of blocks thicks the "shell" should be, use 0 for solid
  1805.    
  1806.     for (var x = 0; x <= size; x++) {
  1807.         for (var y = 0; y <= size; y++) {
  1808.             for (var z = 0; z <= size; z++) {
  1809.            
  1810.                 pos = vec.add(x - size/2 + .5, y - size/2 + .5, z - size/2 + .5);
  1811.                 distance = getDistance(vec, pos);
  1812.                
  1813.                 if (distance > size/2)  {continue;}
  1814.                 if ((hollow != 0) && (distance <= (size/2 - hollow))) {continue;}
  1815.  
  1816.                 session.setBlock(pos, block);
  1817.            
  1818.             }
  1819.         }
  1820.     }
  1821.  
  1822. }
  1823.  
  1824. //////////////////////////////////////////////////////////
  1825. //              Tree Creation Functions
  1826. //////////////////////////////////////////////////////////
  1827.  
  1828. function CreateBush(vec, session, size, woodBlock, leafBlock)   {
  1829.    
  1830.     //var size = checkFlag("s", 3) ? parseInt(checkFlag("s"))* (1+Math.random()*.2) : (Math.random() * (trees['bush'].maxChg)) + trees['bush'].minSize;
  1831.     //var woodBlock = checkFlag("w") ? parseBlock(checkFlag("w")) : trees['bush'].woodBlock;
  1832.     //var leafBlock = checkFlag("l") ? parseBlock(checkFlag("l")) : trees['bush'].leafBlock;
  1833.     //size = gSize != -1 ? gSize + (gSize * (1+Math.random()*.2)) : size;
  1834.    
  1835.     if (checkFlag("c", 3))
  1836.         CreateLeafClump(size, vec.add(0,1*invert,0), leafBlock, session);
  1837.     else   
  1838.         CreateLeafSphere(size, 2*invert, .95, 0, vec.add(0,1*invert,0), leafBlock, session);
  1839.    
  1840.     session.setBlock(vec.add(0,1*invert,0), woodBlock);
  1841. }
  1842.  
  1843. function CreateSmallTree(vec, session, size, woodBlock, leafBlock)  {
  1844.  
  1845.     for (var y = 1; y <= size; y++)     {
  1846.         session.setBlock(vec.add(0,y*invert,0), woodBlock);
  1847.     }
  1848.    
  1849.     if (checkFlag("c", 3))  {
  1850.         CreateLeafClump(size*.7, vec.add(0,y*invert,0), leafBlock, session);
  1851.     }
  1852.     else    {  
  1853.         CreateLeafSphere(size, (3+(size*.1))*invert , .9, 0, vec.add(0,y*invert,0), leafBlock, session);
  1854.     }
  1855.    
  1856. }
  1857.  
  1858. function CreateStickTree(vec, session, size, woodBlock, leafBlock)  {
  1859.  
  1860.     //var size = checkFlag("s") ? parseInt(checkFlag("s"))* (1+Math.random()*.2) : (Math.random() * (trees['stick'].maxChg)) + trees['stick'].minSize;
  1861.     //var woodBlock = checkFlag("w") ? parseBlock(checkFlag("w")) : trees['stick'].woodBlock;
  1862.     //var leafBlock = checkFlag("l") ? parseBlock(checkFlag("l")) : trees['stick'].leafBlock;
  1863.     //size = gSize != -1 ? gSize + (gSize * (1+Math.random()*.2)) : size;
  1864.  
  1865.     for (var y = 1; y <= size; y++)     {
  1866.         session.setBlock(vec.add(0,y*invert,0), woodBlock);
  1867.     }
  1868.  
  1869. }
  1870.  
  1871. function CreateMediumTree(vec, session, size, woodBlock, leafBlock) {
  1872.  
  1873.     for (var y = 1; y <= size; y++)     {
  1874.        
  1875.         var randDir = getRandomXZVec();
  1876.         var sideDir = getRandomXZSide(randDir);
  1877.         var branchLength = (size*trees['medium'].branchSize) + (Math.random()*(size*trees['medium'].branchSize));
  1878.        
  1879.         for(branch = 1; branch < branchLength; branch++)    {
  1880.                 var newPnt = vec.add(randDir.getX()*branch, (y*invert)+(branch/2*invert), randDir.getZ()*branch);
  1881.                 var newPnt = newPnt.add(sideDir.getX()*(branch/2), 0, sideDir.getZ()*(branch/2));
  1882.                 session.setBlock(newPnt, woodBlock);
  1883.         }
  1884.         session.setBlock(newPnt.add(0,1*invert,0), woodBlock);
  1885.        
  1886.         if (checkFlag("c", 3))
  1887.             CreateLeafClump(trees['medium'].leafSize/2+1, newPnt.add(0,2*invert,0), leafBlock, session);
  1888.         else
  1889.             CreateLeafSphere(trees['medium'].leafSize, 3*invert, .9, 0, newPnt.add(0,2*invert,0), leafBlock, session);
  1890.  
  1891.         session.setBlock(vec.add(0,y*invert,0), woodBlock);
  1892.     }
  1893.     if (checkFlag("c", 3))
  1894.         CreateLeafClump(6, vec.add(0,y*invert,0), leafBlock, session);
  1895.     else
  1896.         CreateLeafSphere(8, 4*invert, .8, 0, vec.add(0,y*invert,0), leafBlock, session);
  1897. }
  1898.  
  1899. function CreateLargeTree(vec, session, size, woodBlock, leafBlock)  {
  1900.  
  1901.     if (size < 9)   {size = 10;}
  1902.  
  1903.     for (var y = 1; y <= size; y++)     {
  1904.        
  1905.         if(Math.random() >= (1 - trees['large'].branchProb))    {
  1906.        
  1907.             var randDir = getRandomXZVec();
  1908.             var sideDir = getRandomXZSide(randDir);
  1909.             var branchLength = (size*trees['large'].branchSize) + (Math.random()*(size*trees['large'].branchSize));
  1910.            
  1911.             for(branch = 1; branch < branchLength; branch++)    {
  1912.                     var newPnt = vec.add(randDir.getX()*branch, (y*invert)+(branch/2*invert), randDir.getZ()*branch);
  1913.                     var newPnt = newPnt.add(sideDir.getX()*(branch/2), 0, sideDir.getZ()*(branch/2));
  1914.                     session.setBlock(newPnt, woodBlock);
  1915.             }
  1916.             session.setBlock(newPnt.add(0,1*invert,0), woodBlock);
  1917.            
  1918.             if (checkFlag("c", 3))
  1919.                 CreateLeafClump(trees['large'].leafSize/2+1, newPnt.add(0,2*invert,0), leafBlock, session);
  1920.             else
  1921.                 CreateLeafSphere(trees['large'].leafSize, 3*invert, .9, 0, newPnt.add(0,2*invert,0), leafBlock, session);
  1922.                
  1923.         }
  1924.        
  1925.         session.setBlock(vec.add(0,y*invert,0), woodBlock);
  1926.     }
  1927.    
  1928.     CreateTrunk(size*.2, size * .3, vec.add(.5, 0, .5), woodBlock, session);
  1929.    
  1930.     if (checkFlag("c", 3))
  1931.         CreateLeafClump(6, vec.add(0,y*invert,0), leafBlock, session);
  1932.     else   
  1933.         CreateLeafSphere(8, 4*invert, .8, 0, vec.add(0,y*invert,0), leafBlock, session);
  1934. }
  1935.  
  1936. function CreateBranchedTree(vec, session, size, woodBlock, leafBlock)   {
  1937.  
  1938.     for (var y = 1; y <= size; y++)     {
  1939.        
  1940.         if(Math.random() >= (1 - trees['branched'].branchProb1))    {
  1941.            
  1942.             var randDir1 = getRandomXZVec();
  1943.             var sideDir1 = getRandomXZSide(randDir1);
  1944.             var branchLength1 = (size*trees['branched'].branchSize1) + (Math.random()*(size*trees['branched'].branchSize1));
  1945.            
  1946.             for(branch1 = 1; branch1 < branchLength1; branch1++)    {
  1947.                 var newPnt = vec.add(randDir1.getX()*branch1, (y*invert)+(branch1/2*invert), randDir1.getZ()*branch1);
  1948.                 newPnt = newPnt.add(sideDir1.getX()*(branch1), 0, sideDir1.getZ()*(branch1));
  1949.                 session.setBlock(newPnt, woodBlock);
  1950.                
  1951.                 if(Math.random() >= (1 - trees['branched'].branchProb2))    {
  1952.  
  1953.                     var randDir2 = getRandomXZVec();
  1954.                     var sideDir2 = getRandomXZSide(randDir2);
  1955.                     var branchLength2 = (size*trees['branched'].branchSize2) + (Math.random()*(size*trees['branched'].branchSize2));
  1956.                    
  1957.                     for(branch2 = 1; branch2 < branchLength2; branch2++)    {
  1958.                         //var newPnt = vec.add(randDir.getX()*branc1h, (y*invert)+(branch2/2*invert)), randDir.getZ()*branch1);
  1959.                         var newPnt2 = newPnt.add(sideDir2.getX()*(branch2/2), 1*invert, sideDir2.getZ()*(branch2/2));
  1960.                         session.setBlock(newPnt2, woodBlock);
  1961.                        
  1962.                     }
  1963.                     session.setBlock(newPnt2.add(0,1*invert,0), woodBlock);
  1964.                     if (checkFlag("c", 3))
  1965.                         CreateLeafClump(trees['branched'].leafSize/2-1, newPnt2.add(0,2*invert,0), leafBlock, session);
  1966.                     else   
  1967.                         CreateLeafSphere(trees['branched'].leafSize, 2*invert, .9, 0, newPnt2.add(0,2*invert,0), leafBlock, session);
  1968.                 }
  1969.             }
  1970.             session.setBlock(newPnt.add(0,1*invert,0), woodBlock);
  1971.            
  1972.             if (checkFlag("c", 3))
  1973.                 CreateLeafClump(trees['branched'].leafSize/2-1, newPnt.add(0,2*invert,0), leafBlock, session);
  1974.             else
  1975.                 CreateLeafSphere(trees['branched'].leafSize, 3*invert, .9, 0, newPnt.add(0,2*invert,0), leafBlock, session);
  1976.                
  1977.         }
  1978.        
  1979.         session.setBlock(vec.add(0,y*invert,0), woodBlock);
  1980.     }
  1981.    
  1982.     CreateTrunk(size*.3, size * .35, vec, woodBlock, session);
  1983.     if (checkFlag("c", 3))
  1984.         CreateLeafClump(6, vec.add(0,y*invert,0), leafBlock, session);
  1985.     else   
  1986.         CreateLeafSphere(8, 4*invert, .8, 0, vec.add(0,y*invert,0), leafBlock, session);
  1987. }
  1988.  
  1989. function CreateRainforestTree(vec, session, size, woodBlock, leafBlock) {
  1990.    
  1991.     for (var y = 1; y <= size; y++)     {
  1992.        
  1993.         if (y > (trees['rainforest'].branchHeight * size))  {
  1994.             var randDir = getRandomXZVec();
  1995.             var sideDir = getRandomXZSide(randDir);
  1996.             var branchLength = (size*trees['rainforest'].branchSize) + (Math.random()*(size*trees['rainforest'].branchSize));
  1997.            
  1998.             if(Math.random() >= (1 - trees['rainforest'].branchProb))   {
  1999.        
  2000.                 for(branch = 1; branch < branchLength; branch++)    {
  2001.                     var newPnt = vec.add(randDir.getX()*branch, (y*invert)+(branch/2*invert), randDir.getZ()*branch);
  2002.                     var newPnt = newPnt.add(sideDir.getX()*(branch/2), 0, sideDir.getZ()*(branch/2));
  2003.                     session.setBlock(newPnt, woodBlock);
  2004.                 }
  2005.                 if (checkFlag("c", 3))
  2006.                     CreateLeafClump(trees['rainforest'].leafSize/2, newPnt.add(0,1*invert,0), leafBlock, session);
  2007.                 else
  2008.                     CreateLeafSphere(trees['rainforest'].leafSize, 2*invert, .95, 0,  newPnt.add(0,1*invert,0), leafBlock, session);
  2009.             }
  2010.         }          
  2011.         session.setBlock(vec.add(0,y*invert,0), woodBlock);
  2012.     }
  2013.    
  2014.     CreateTrunk(size*.15, size * .2, vec.add(.5, 0, .5), woodBlock, session);
  2015.    
  2016.     if (checkFlag("c", 3))
  2017.         CreateLeafClump(trees['rainforest'].leafSize/2, vec.add(0,y*invert,0), leafBlock, session);
  2018.     else
  2019.         CreateLeafSphere(trees['rainforest'].leafSize, 3*invert, .9, 0,  vec.add(0,y*invert,0), leafBlock, session);
  2020.  
  2021. }
  2022.  
  2023. function CreatePalmTree(vec, session, size, woodBlock, leafBlock)   {
  2024.  
  2025.     var randDir = getRandomXZVec();
  2026.     var sideDir = getRandomXZSide(randDir);
  2027.    
  2028.     for (var y = 0; y < size; y++)      {
  2029.         var setVec = vec.add(randDir.getX()*y*.5, (y+1)*invert, randDir.getZ()*y*.5);
  2030.         var setVec = setVec.add(sideDir.getX()*y*.5, 0, sideDir.getZ()*y*.5);
  2031.        
  2032.         session.setBlock(setVec, woodBlock);
  2033.     }
  2034.     if (checkFlag("l"))
  2035.         CreateShape(shapes['PalmLeaf'], setVec, 361, new SingleBlockPattern(parseBlock(checkFlag("l"))), -1, session);
  2036.     else
  2037.         CreateShape(shapes['PalmLeaf'], setVec, 361, airMat, -1, session);
  2038.     session.setBlock(setVec, woodBlock);
  2039. }
  2040.  
  2041. function CreateSpikeTree(vec, session, size, woodBlock, leafBlock)  {
  2042.  
  2043.     //var size = checkFlag("s") ? parseInt(checkFlag("s"))* (1+Math.random()*.2) : (Math.random() * (trees['spike'].maxChg)) + trees['spike'].minSize;
  2044.     //var woodBlock = checkFlag("w") ? parseBlock(checkFlag("w")) : trees['spike'].woodBlock;
  2045.     //var leafBlock = checkFlag("l") ? parseBlock(checkFlag("l")) : trees['spike'].leafBlock;
  2046.     //size = gSize != -1 ? gSize + (gSize * (1+Math.random()*.2)) : size;
  2047.    
  2048.     for (var y = 1; y <= size; y++)     {
  2049.        
  2050.         if(Math.random() >= (1 - trees['spike'].branchProb1))   {
  2051.        
  2052.             var randDir1 = getRandomXZVec();
  2053.             var sideDir1 = getRandomXZSide(randDir1);
  2054.             var branchLength1 = (size*trees['spike'].branchSize1) + (Math.random()*(size*trees['spike'].branchSize1));
  2055.            
  2056.             //var maxRange = (Math.random() * 5)+.5;
  2057.            
  2058.             for(branch1 = 1; branch1 < branchLength1; branch1++)    {
  2059.                 var newPnt = vec.add(randDir1.getX()*branch1, y+(branch1/2), randDir1.getZ()*branch1);
  2060.                 newPnt = newPnt.add(sideDir1.getX()*(branch1), 0, sideDir1.getZ()*(branch1));
  2061.                 session.setBlock(newPnt, woodBlock);
  2062.  
  2063.                 if(Math.random() >= (1 - trees['spike'].branchProb2))   {
  2064.  
  2065.                     var randDir2 = getRandomXZVec();
  2066.                     var sideDir2 = getRandomXZSide(randDir2);
  2067.                     var branchLength2 = (size*trees['spike'].branchSize2) + (Math.random()*(size*trees['spike'].branchSize2));
  2068.                    
  2069.                     for(branch2 = 1; branch2 < branchLength2; branch2++)    {
  2070.                         //var newPnt = vec.add(randDir.getX()*branc1h, y+(branch/2), randDir.getZ()*branch1);
  2071.                         var newPnt2 = newPnt.add(sideDir2.getX()*(branch2/2), 0, sideDir2.getZ()*(branch2/2));
  2072.                         session.setBlock(newPnt2, woodBlock);
  2073.                        
  2074.                     }
  2075.                     //CreateSpike(newPnt, newPnt2, trees['spike'].woodBlock, session, 2);
  2076.                    
  2077.                     session.setBlock(newPnt2.add(0,1,0), woodBlock);
  2078.                     if (checkFlag("c", 3))
  2079.                         CreateLeafClump(trees['spike'].leafSize/2-1, newPnt2.add(0,2*invert,0), leafBlock, session);
  2080.                     else   
  2081.                         CreateLeafSphere(trees['spike'].leafSize, 2*invert, .9, 0, newPnt2.add(0,2*invert,0), leafBlock, session);
  2082.                 }
  2083.             }
  2084.            
  2085.             CreateSpike(vec.add(0,y,0), newPnt, woodBlock, session, 3);
  2086.             if (checkFlag("c", 3))
  2087.                 CreateLeafClump(trees['spike'].leafSize/2-1, newPnt.add(0,2*invert,0), leafBlock, session);
  2088.             else
  2089.                 CreateLeafSphere(trees['spike'].leafSize, 3*invert, .9, 0, newPnt.add(0,2*invert,0), leafBlock, session);
  2090.                
  2091.         }
  2092.        
  2093.     }
  2094.     CreateSpike(vec, vec.add(0,size,0), trees['spike'].woodBlock, session, size/10);
  2095.    
  2096.     if (checkFlag("c", 3))
  2097.         CreateLeafClump(6, vec.add(0,y*invert,0), leafBlock, session);
  2098.     else   
  2099.         CreateLeafSphere(8, 4*invert, .8, 0, vec.add(0,y*invert,0), leafBlock, session);
  2100.  
  2101. }
  2102.  
  2103. function CreateMushroom(vec, session, size, woodBlock, leafBlock)   {
  2104.  
  2105.     leafBlock = (gMat == airMat) ? new SingleBlockPattern(leafBlock) : gMat;
  2106.  
  2107.     var randDir = getRandomXZVec();
  2108.     var sideDir = getRandomXZSide(randDir);
  2109.     //var slopeMod = .3;
  2110.    
  2111.     for (var y = 0; y < size *.6; y++)      {
  2112.        
  2113.         var slopeMod = 1-(y/(size*1.1));
  2114.         var setVec = vec.add(randDir.getX()*y*slopeMod, (y+1)*invert, randDir.getZ()*y*slopeMod);
  2115.         var setVec = setVec.add(sideDir.getX()*y*slopeMod, 0, sideDir.getZ()*y*slopeMod);
  2116.        
  2117.         CreateLeafSphere(size/3, 2 , .98, 0, setVec, woodBlock, session)
  2118.     }
  2119.     var slopeMod = 0;
  2120.    
  2121.     for (var y = 0; y < size * .4; y++)     {
  2122.        
  2123.         //var slopeMod = 1-(y/size);
  2124.         var newVec = setVec.add(randDir.getX()*y*slopeMod/2, (y+1)*invert, randDir.getZ()*y*slopeMod/2);
  2125.         var newVec = newVec.add(sideDir.getX()*y*slopeMod/2, 0, sideDir.getZ()*y*slopeMod/2);
  2126.         //var newVec = setVec.add(0, (y+1)*invert, 0);
  2127.         CreateLeafSphere(size/3, 2 , .98, 0, newVec, woodBlock, session)
  2128.     }
  2129.    
  2130.     CreateLeafSphere(size, (size/2)*invert, 1, (size/8), newVec.add(0,-(size/2-size/8)*invert+1,0), leafBlock, session)
  2131. }
  2132.  
  2133. //////////////////////////////////////////////////////////
  2134. //              Player Tool Commands
  2135. //////////////////////////////////////////////////////////
  2136.  
  2137. function BuildTest(vec, session)    {
  2138.  
  2139.     var timeOut = context.getConfiguration().scriptTimeout;
  2140.     player.print(text.White + "Script timeout is currently set to " + text.Gold + timeOut + " (" + (timeOut/1000) + "s).");
  2141.     if (timeOut < 10000 )
  2142.         player.print(text.White + "This is a little low, I suggest increasing to at least" + text.Gold + " 10000 (10s).");
  2143.  
  2144.     return;
  2145.        
  2146. }
  2147.  
  2148. function HelpText(cmdType)  {
  2149.    
  2150.     if (cmdType != 1)   {
  2151.         var helpArg = argv.length > 2 ? argv[2] : -1;
  2152.         var helpMode = parseMode(helpArg)
  2153.     }
  2154.     else{
  2155.         var helpArg = argv.length > 1 ? argv[1] : 1;
  2156.         var helpMode = parseMode(helpArg)
  2157.     }  
  2158.    
  2159.     if (helpMode != -1) {
  2160.        
  2161.         var keyStr = [];   
  2162.         var argStr = [];
  2163.        
  2164.         for (var keyInc in tools[helpMode].keys)    {
  2165.             keyStr = keyStr + text.Red + tools[helpMode].keys[keyInc] + text.White + "|";
  2166.         }
  2167.         for (var argInc in tools[helpMode].args)    {
  2168.             argStr = argStr + (text.White + "<");
  2169.             if (String(tools[helpMode].aFlags[argInc]).length > 0)  {
  2170.                 argStr = argStr + (text.Red + tools[helpMode].aFlags[argInc] + text.Gold + text.Arrow);
  2171.             }
  2172.             argStr = argStr + (text.Red + tools[helpMode].args[argInc] + text.White + ">");
  2173.         }
  2174.  
  2175.         player.print("\n" + text.Gold + tools[helpMode].name + " " + text.Gold + argStr);
  2176.         player.print(text.White + text.Italics + tools[helpMode].note);
  2177.         player.print(text.White + "Keywords  |" + text.Red + keyStr );
  2178.     }
  2179.     else    {
  2180.  
  2181.         player.print("\n" + text.Gold + text.Italics + "Build Commands " + text.Red + "v" + version + text.White + " by inHaze \n \n");
  2182.         player.print(text.White + "Type " + text.Red + "/cs build list"  + text.White + " or " + text.Red + "/cs build commands" + text.White + " for command usage.");
  2183.         player.print(text.White + "Type " + text.Red + "/cs build ? " + text.Gold + "command" + text.White + " for detailed info on any command.");
  2184.     }
  2185.    
  2186. }
  2187.  
  2188. function CommandList()  {
  2189.    
  2190.     var endStr =  [];
  2191.     var strList =  [];
  2192.    
  2193.     for (inc in tools)  {
  2194.         var argStr = [];
  2195.         var comStr = [];
  2196.         for (var argInc in tools[inc].args) {
  2197.             argStr = argStr + (text.White + "<");
  2198.             if (String(tools[inc].aFlags[argInc]).length > 0)   {
  2199.                 argStr = argStr + (text.Red + tools[inc].aFlags[argInc] + text.Gold + text.Arrow);
  2200.             }
  2201.             argStr = argStr + (text.Red + tools[inc].args[argInc] + text.White + ">");
  2202.         }
  2203.    
  2204.          comStr = comStr + (text.Gold + tools[inc].keys[0] + " \u00A7c" + argStr + "\n");
  2205.          comStr = comStr + (text.White + text.Italics + tools[inc].note);
  2206.          strList.push (comStr);
  2207.     }
  2208.     strList.sort();
  2209.     for (inc in strList)    {
  2210.         endStr = (endStr + strList[inc] + "\n");
  2211.     }
  2212.     player.print("\n" + text.White + "Command List - Type " + text.Red + "/cs build ? " + text.Gold + "command" + text.White + " for detailed info. \n \n");
  2213.     player.print(endStr);
  2214.     //saveFile("CommandList", endStr);
  2215.    
  2216. }
  2217.  
  2218. function CommandListShort() {
  2219.    
  2220.     var names = [];
  2221.     var listStr = text.White + "[";
  2222.    
  2223.     for (inc in tools)  {
  2224.         names.push (String(tools[inc].keys[0]))
  2225.     }
  2226.     names.sort();
  2227.     for (inc in names)  {
  2228.         listStr = listStr + (text.Gold + names[inc] + text.White + " | ");
  2229.     }
  2230.    
  2231.     listStr = listStr + "]";
  2232.     player.print("\n" + text.White + "Short Command List - Use " + text.Red + "/cs build commands" + text.White + " for a full listing \n \n");
  2233.     player.print(listStr);
  2234. }
  2235.  
  2236. function ClearNature(vec, session)  {
  2237.  
  2238.     //var clearType = checkFlag("s") ? parseInt(checkFlag("s")) : 20;
  2239.     var size = checkFlag("s") ? parseInt(checkFlag("s")) : 20;
  2240.     size = gSize != -1 ? gSize + (gSize * Math.random()*.2) : size;
  2241.    
  2242.     var blackList = [6,17,18,31,32,37,38,39,40,59,78,81,83,86,103,104,105,106,111,115,127,141,142];
  2243.    
  2244.     for (var x = 0; x <= size; x++) {
  2245.         for (var z = 0; z <= size; z++) {
  2246.             for (var y = size; y >= 0; y--) {                  
  2247.                 pos = vec.add(x - size/2 + .5, y - size/2 + .5, z - size/2 + .5);
  2248.                 distance = getDistance(vec, pos);
  2249.  
  2250.                 if (distance > size/2)  {continue;}
  2251.                 if (blackList.indexOf(session.getBlock(pos).getType()) == -1)   {continue;}
  2252.  
  2253.                 session.setBlock(pos, new BaseBlock(0));
  2254.  
  2255.             }
  2256.         }
  2257.     }
  2258.  
  2259. }
  2260.  
  2261. function BuildTree(vec, session)    {
  2262.    
  2263.     var treeType = argv.length > 2 ? String(argv[2]).toLowerCase() : "";
  2264.  
  2265.     typeCheck = -1;
  2266.     for (inc in trees)  {
  2267.         if (treeType == String(inc).toLowerCase())
  2268.             typeCheck = 1;
  2269.     }
  2270.     if (typeCheck == -1)    {
  2271.         var tmpStr = text.White + "[ ";
  2272.         for (inc in trees)  {tmpStr = tmpStr + text.Gold + String(inc).toLowerCase() + text.White + " | ";}
  2273.        
  2274.         player.print("\n" + text.Red + "Error: " + text.White + "Tree type " + text.Gold + treeType + text.White + " not found.");
  2275.         player.print(text.White + text.Italics + "Available tree types: \n" + tmpStr + "]");
  2276.         return;
  2277.     }
  2278.    
  2279.     var size = checkFlag("s", 3) ? parseInt(checkFlag("s", 3))* (1+Math.random()*.2) : (Math.random() * (trees[treeType].maxChg)) + trees[treeType].minSize;
  2280.     var woodBlock = checkFlag("w", 3) ? parseBlock(checkFlag("w", 3)) : trees[treeType].woodBlock;
  2281.     var leafBlock = checkFlag("l", 3) ? parseBlock(checkFlag("l", 3)) : trees[treeType].leafBlock;
  2282.     size = gSize != -1 ? gSize + (gSize * (1+Math.random()*.2)) : size;
  2283.    
  2284.     trees[treeType].mySub(vec, session, size, woodBlock, leafBlock);
  2285.    
  2286. }
  2287.  
  2288. function BuildShape(vec, session)   {
  2289.  
  2290.     if(myShape.length != 0) {
  2291.         var mat = (gMat == airMat) ? airMat : gMat;
  2292.         var excludeID = checkFlag("!") ? parseBlock(checkFlag("!")).getType() : -1;
  2293.        
  2294.         var angle = checkFlag("<") ? parseFloat(checkFlag("<")) : getDirection().rightAngle;
  2295.         angle = checkFlag("<") == 360 ? getDirection().yaw : angle;
  2296.        
  2297.         CreateShape(myShape['TMP'], vec, angle, mat, excludeID, session);
  2298.     }
  2299.     else    {
  2300.         loadShape(vec, session);
  2301.     }
  2302.  
  2303. }
  2304.  
  2305. function BuildShapeKit(vec, session){
  2306.  
  2307.     if (myKit.length != 0)  {
  2308.         for (var inc in myKit)  {
  2309.            
  2310.             if (player.getItemInHand() == myKit[inc].item)  {
  2311.                 var mat = ((gMat == airMat)) ? airMat : gMat;
  2312.                 var excludeID = checkFlag("!") ? parseBlock(checkFlag("!")).getType() : -1;
  2313.                
  2314.                 var angle = checkFlag("<") ? parseFloat(checkFlag("<")) : getDirection().rightAngle;
  2315.                 angle = checkFlag("<") == 360 ? getDirection().yaw : angle;
  2316.                
  2317.                 CreateShape(myShape[inc], vec, angle, mat, excludeID, session);
  2318.             }
  2319.         }
  2320.     }
  2321.     else    {
  2322.    
  2323.         var tmpKit = new Array();
  2324.         var tool = new Array();
  2325.         var fileName = String(argv[2]);
  2326.  
  2327.         var aStr = fileName.slice((fileName.length)-4).toLowerCase();
  2328.         if (aStr == ".kit") {fileName = String(argv[2]).slice(0, String(argv[2]).length-4).toLowerCase()};
  2329.  
  2330.         var file = context.getSafeFile("shapes", String(fileName + '.kit'));
  2331.         if(!file.exists()){
  2332.             player.print(text.Red + "Error! " + text.Gold + "Could not find kit file: " + text.White + text.Italics + file);
  2333.             return false;
  2334.         }
  2335.        
  2336.         player.print(text.White + text.Italics + "Loading shapes from kit file: " + text.Gold + fileName + ".kit");
  2337.         var kitStr = loadFile(fileName, 3);
  2338.         tmpKit = parseKitFile(kitStr);
  2339.  
  2340.         for (inc in tmpKit) {       //this is where the brushes get set to the loaded shapeKit list
  2341.             context.getSession().setTool(tmpKit[inc].item, null)
  2342.             tool[inc] = context.getSession().getBrushTool(tmpKit[inc].item);
  2343.             tool[inc].setFill(airMat);
  2344.             tool[inc].setBrush(brush, "worldedit.brush.buildShapeKit");
  2345.         }
  2346.    
  2347.         myKit = tmpKit;
  2348.         loadShapeKit(vec, session, tmpKit);
  2349.  
  2350.     }
  2351.  
  2352. }
  2353.  
  2354. function BuildPaint(vec, session)   {
  2355.  
  2356.     if(myShape.length != 0) {
  2357.         mat = ((gMat == airMat)) ? airMat : gMat;
  2358.         excludeID = checkFlag("!") ? parseBlock(checkFlag("!")).getType() : -1;
  2359.        
  2360.         var angle = checkFlag("<") ? parseFloat(checkFlag("<")) : getDirection().rightAngle;
  2361.         angle = checkFlag("<") == 360 ? getDirection().yaw : angle;
  2362.        
  2363.         CreateShape(myShape['TMP'], vec, angle, mat, excludeID, session);
  2364.     }
  2365.     else    {
  2366.         loadShape(vec, session);
  2367.     }
  2368.    
  2369.     generateError();
  2370. }
  2371.  
  2372. function BuildGrassPatch(vec, session)  {
  2373.  
  2374.     var size = checkFlag("s") ? parseInt(checkFlag("s")) : 15;
  2375.     var density = checkFlag("d") ? parseFloat(checkFlag("d")) : .25;
  2376.     size = gSize != -1 ? gSize + (gSize * Math.random()*.2) : size;
  2377.    
  2378.     var blackList = [0,6,31,32,37,38,39,40,81,106];
  2379.     var whiteList = [2,3,88];
  2380.    
  2381.     for (var x = 0; x <= size; x++) {
  2382.         for (var z = 0; z <= size; z++) {
  2383.             for (var y = size; y >= 0; y--) {                  
  2384.                 pos = vec.add(x - size/2 + .5, y - size/2 + .5, z - size/2 + .5);
  2385.                 distance = getDistance(vec, pos);
  2386.  
  2387.                 if (distance > size/2)  {continue;}
  2388.                 if (blackList.indexOf(session.getBlock(pos).getType()) == -1)   {continue;}
  2389.                 if (blackList.indexOf(session.getBlock(pos.add(0,1,0)).getType()) == -1)    {continue;}
  2390.                 if (whiteList.indexOf(session.getBlock(pos.add(0,-1,0)).getType()) == -1)   {continue;}    
  2391.                 if (density > Math.random())    {
  2392.                
  2393.                     session.setBlock(pos, getListBlock(blocks["plants"].list));
  2394.  
  2395.                 }
  2396.             }
  2397.         }
  2398.     }
  2399.  
  2400. }
  2401.  
  2402. function BuildStickPatch(vec, session)  {
  2403.  
  2404.     var size = checkFlag("s") ? parseInt(checkFlag("s")) : 15;
  2405.     var density = checkFlag("d") ? parseFloat(checkFlag("d")) : .25;
  2406.     var block = checkFlag("b") ? parseBlock(checkFlag("b")) :  trees['Stick'].woodBlock;
  2407.     size = gSize != -1 ? gSize + (gSize * Math.random()*.2) : size;
  2408.     var mat = (gMat == airMat) ? new SingleBlockPattern(block) : gMat;
  2409.        
  2410.     if (checkFlag("l")) {
  2411.         var minSize = parseBlockExtra(checkFlag("l")).block.getType();
  2412.         var maxChg = parseBlockExtra(checkFlag("l")).extra;
  2413.     }
  2414.     else    {
  2415.         var minSize = trees['Stick'].minSize;
  2416.         var maxChg = trees['Stick'].maxChg;
  2417.     }
  2418.    
  2419.     var blackList = [0,6,31,32,37,38,39,40,81,106];     //don't attach to these blocks
  2420.     //var whiteList = [2,3,88];
  2421.    
  2422.     for (var x = 0; x <= size; x++) {
  2423.         for (var z = 0; z <= size; z++) {
  2424.             for (var y = size; y >= 0; y--) {                  
  2425.                 pos = vec.add(x - size/2 + .5, y - size/2 + .5, z - size/2 + .5);
  2426.                 distance = getDistance(vec, pos);
  2427.  
  2428.                 if (distance > size/2)  {continue;}
  2429.                 if (blackList.indexOf(session.getBlock(pos).getType()) == -1)   {continue;}
  2430.                 if (blackList.indexOf(session.getBlock(pos.add(0,1*invert,0)).getType()) == -1) {continue;}
  2431.                 if (blackList.indexOf(session.getBlock(pos.add(0,-1*invert,0)).getType()) != -1)    {continue;}    
  2432.                
  2433.                 if (density > Math.random())    {
  2434.                     var height = (Math.random() * maxChg) + minSize;
  2435.                    
  2436.                     for (var inc = 0; inc < height; inc++)  {
  2437.                         session.setBlock(pos.add(0,inc*invert,0), mat);
  2438.                     }
  2439.  
  2440.                 }
  2441.             }
  2442.         }
  2443.     }
  2444. }
  2445.  
  2446. function BuildOverlayPatch(vec, session){
  2447.  
  2448.     var block = [];
  2449.     var depth = [];
  2450.     var size = checkFlag("s") ? parseInt(checkFlag("s")) : 15;
  2451.     size = gSize != -1 ? gSize : size;
  2452.    
  2453.    
  2454.     if (checkFlag("t")) {
  2455.         block[0] = parseBlockExtra(checkFlag("t")).block;
  2456.         depth[0] = parseBlockExtra(checkFlag("t")).extra;
  2457.     }
  2458.     else    {
  2459.         block[0] = new BaseBlock(2, 0);
  2460.         depth[0] = 0;
  2461.     }
  2462.    
  2463.     if (checkFlag("m")) {
  2464.         block[1] = parseBlockExtra(checkFlag("m")).block;
  2465.         depth[1] = parseBlockExtra(checkFlag("m")).extra;
  2466.     }
  2467.     else    {
  2468.         block[1] = new BaseBlock(3, 0);
  2469.         depth[1] = 0;
  2470.     }
  2471.    
  2472.     if (checkFlag("e")) {
  2473.         block[2] = parseBlockExtra(checkFlag("e")).block;
  2474.         depth[2] = parseBlockExtra(checkFlag("e")).extra;
  2475.     }
  2476.     else    {
  2477.         block[2] = new BaseBlock(1, 0);
  2478.         depth[2] = 0;
  2479.     }
  2480.    
  2481.     block[0] = (gMat == airMat) ? new SingleBlockPattern(block[0]) : gMat;
  2482.    
  2483.     if (depth[0] < 1)   {
  2484.         depth[0] = 1;
  2485.         depth[1] = 2;
  2486.         depth[2] = 3;
  2487.     }
  2488.    
  2489.     var whiteList = [0,6,17,18,31,32,37,38,39,40,78,81,83,86,106];              //The blocks allowed to be over the natural block
  2490.     var greenList = [1,2,3,12,13,14,15,16,21,24,56,73,82,87,88,110,121,129];    //List of natural blocks that should be changed
  2491.    
  2492.     for (var x = 0; x <= size; x++) {
  2493.         for (var y = 0; y <= size; y++) {
  2494.             for (var z = 0; z <= size; z++) {
  2495.                            
  2496.                 pos = vec.add(x - size/2 + .5, y - size/2 + .5, z - size/2 + .5);
  2497.                 distance = getDistance(vec, pos);
  2498.  
  2499.                 if (distance > size/2)  {continue;}
  2500.                 if(!checkFlag("a")) {
  2501.                     if (greenList.indexOf(session.getBlock(pos).getType()) == -1)   {continue;}
  2502.                     if (whiteList.indexOf(session.getBlock(pos.add(0,1*invert,0)).getType()) == -1) {continue;}
  2503.                 }
  2504.                 else    {
  2505.                     if (session.getBlock(pos).getType() == 0) {continue;}
  2506.                     if (session.getBlock(pos.add(0,1*invert,0)).getType() != 0) {continue;}
  2507.                 }
  2508.                
  2509.                 var totalDepth = depth[0] + depth[1] + depth[2];
  2510.                 for (var inc = 0; inc < totalDepth; inc++)  {
  2511.                     if (!checkFlag("a"))
  2512.                         if (greenList.indexOf(session.getBlock(pos.add(0,(0-inc)*invert,0)).getType()) == -1)   {break;}
  2513.                     if (inc < depth[0]) {
  2514.                         if ((block[0].next(0,0,0).getType() == 0) && (block[0].next(0,0,0).getData() != 0)) {continue;}     //If air is used, and has a non zero data value skip it
  2515.                         session.setBlock(pos.add(0,(0-inc)*invert,0), block[0]);
  2516.                    
  2517.                     }
  2518.                     else if (inc >= depth[0] && inc < (depth[0] + depth[1]))    {
  2519.                         if ((block[1].getType() == 0) && (block[1].getData() != 0)) {continue;}
  2520.                         session.setBlock(pos.add(0,(0-inc)*invert,0), block[1]);
  2521.                     }
  2522.                     else {
  2523.                         if ((block[2].getType() == 0) && (block[2].getData() != 0)) {continue;}
  2524.                         session.setBlock(pos.add(0,(0-inc)*invert,0), block[2]);
  2525.                     }
  2526.                 }
  2527.             }
  2528.         }
  2529.     }
  2530. }
  2531.  
  2532. function BuildFlat(vec, session)    {
  2533.  
  2534.     var size = checkFlag("s") ? parseInt(checkFlag("s")) : 15;
  2535.     var block = checkFlag("b") ? parseBlock(checkFlag("b")) : new BaseBlock(2, 0);
  2536.     var depth = checkFlag("d") ? parseFloat(checkFlag("d")) : 62;
  2537.     var mat = (gMat == airMat) ? new SingleBlockPattern(block) : gMat;
  2538.     size = gSize != -1 ? gSize : size;
  2539.  
  2540.    
  2541.     var fillList = [0,8,9,10,11];   //fill these blocks if they are in the path
  2542.  
  2543.     for (var x = 0; x <= size; x++) {
  2544.         for (var y = 0; y <= size; y++) {
  2545.             for (var z = 0; z <= size; z++) {
  2546.                            
  2547.                 pos = vec.add(x - size/2 + .5, parseInt(y - size/2 + .5), z - size/2 + .5);
  2548.                 distance = getDistance(vec, pos);
  2549.                 totalDepth = pos.getY() - depth;
  2550.                
  2551.                 if (distance > size/2)  {continue;}
  2552.                 if ((session.getBlock(pos).getType() == 0) && (totalDepth != 0))    {continue;}
  2553.                
  2554.                 if (totalDepth > 0) {           //Clearing Down
  2555.                     for (var inc = 0; inc <= totalDepth; inc++) {
  2556.  
  2557.                         if (mat.next(0,0,0).getType() == 0) {totalDepth-10;}
  2558.                         if (inc == totalDepth)  {
  2559.                             if (mat.next(0,0,0).getType() == 0) {continue;}     //Skip if air is used
  2560.                             session.setBlock(pos.add(0,(0-inc),0), mat);
  2561.                         }
  2562.                         else    {
  2563.                             session.setBlock(pos.add(0,(0-inc),0), new BaseBlock(0));
  2564.                         }
  2565.                     }
  2566.                 }
  2567.                 else if (totalDepth < 0)    {       //Filling Up
  2568.                     for (var inc = 0; inc >= totalDepth; inc--) {
  2569.                         if (session.getBlock(pos.add(0,(0-inc),0)).getType() == 0)  {
  2570.                             session.setBlock(pos.add(0,(0-inc),0), mat);
  2571.                         }
  2572.  
  2573.                     }
  2574.                 }
  2575.                
  2576.                
  2577.                 else if (totalDepth == 0)   {
  2578.                     session.setBlock(pos, mat)
  2579.                     for (inc = 1; inc < 256; inc++) {
  2580.                         if (fillList.indexOf(session.getBlock(pos.add(0,(0-inc),0)).getType()) == -1)   {break;}
  2581.                         session.setBlock(pos.add(0,(0-inc),0), mat);
  2582.                        
  2583.                     }
  2584.                 }
  2585.             }
  2586.         }
  2587.     }
  2588. }
  2589.  
  2590. function BuildSpike(vec, session)   {
  2591.  
  2592.     var size = checkFlag("s") ? parseInt(checkFlag("s")) : 8;
  2593.     var block = checkFlag("b") ? parseBlock(checkFlag("b")) : new BaseBlock(1, 0);
  2594.     var mat = (gMat == airMat) ? new SingleBlockPattern(block) : gMat;
  2595.     size = gSize != -1 ? gSize : size;
  2596.    
  2597.     if (checkFlag("l")) {
  2598.         var minSize = parseBlockExtra(checkFlag("l")).block.getType();
  2599.         var maxChg = parseBlockExtra(checkFlag("l")).extra;
  2600.     }
  2601.     else    {
  2602.         var minSize = 50;
  2603.         var maxChg = 15;
  2604.     }
  2605.  
  2606.     var length = (Math.random() * maxChg) + minSize;
  2607.     var end = getDistanceVec(vec, player.getBlockIn(), length);
  2608.  
  2609.     CreateSpike(vec, end, mat, session, size);
  2610.    
  2611. }
  2612.  
  2613. function BuildVines(vec, session)   {
  2614.  
  2615.     var size = checkFlag("s") ? parseInt(checkFlag("s")) : 12;
  2616.     var density = checkFlag("d") ? parseFloat(checkFlag("d")) : .25;
  2617.     var block = checkFlag("b") ? parseBlock(checkFlag("b")) :  new BaseBlock(BlockID.VINE, 0);
  2618.     var length = checkFlag("l") ? parseInt(checkFlag("l")) : 12;
  2619.     var mat = (gMat == airMat) ? new SingleBlockPattern(block) : gMat;
  2620.     size = gSize != -1 ? gSize : size;
  2621.    
  2622.     var rand = new java.util.Random();
  2623.  
  2624.     var blackList = [0,6,8,9,31,32,37,38,39,40,81,83,86,106];       //Do not place vines on these blocks
  2625.  
  2626.     for (var x = 0; x <= size; x++) {
  2627.         for (var y = 0; y <= size; y++) {
  2628.             for (var z = 0; z <= size; z++) {
  2629.                            
  2630.                 pos = vec.add(x - size/2 + .5, y - size/2 + .5, z - size/2 + .5);
  2631.                 var distance = getDistance(vec, pos);
  2632.                 var curBlock = session.getBlock(pos);
  2633.  
  2634.                 if (distance > size/2)  {continue;}
  2635.                 if (Math.random() > density) {continue;}
  2636.                 if (curBlock.getType() != 0) {continue;}
  2637.                
  2638.                 var vines = new Array();
  2639.                 vines[1] = new BaseBlock(BlockID.VINE, 8);  
  2640.                 vines[2] = new BaseBlock(BlockID.VINE, 2);  
  2641.                 vines[3] = new BaseBlock(BlockID.VINE, 1);  
  2642.                 vines[4] = new BaseBlock(BlockID.VINE, 4);
  2643.  
  2644.                 var blockFaces = new Array();
  2645.                 blockFaces[1] = session.getBlockType(pos.add(1,0,0));
  2646.                 blockFaces[2] = session.getBlockType(pos.add(-1,0,0));
  2647.                 blockFaces[3] = session.getBlockType(pos.add(0,0,1));
  2648.                 blockFaces[4] = session.getBlockType(pos.add(0,0,-1));
  2649.                
  2650.                 var solidSide = new Array();
  2651.                 for (var inc = 1; inc <= 4; inc++) {
  2652.                    
  2653.                 if ((blackList.indexOf(blockFaces[inc]) != -1) || (blockFaces[inc] == mat.next(0,0,0).getType())) {continue;}
  2654.                     if (blockFaces[inc] != 0) {
  2655.                         solidSide.push(inc)
  2656.                     }                                              
  2657.                 }
  2658.                 if ((solidSide.length >= 1)){
  2659.                     randomSide = solidSide[(rand.nextInt(solidSide.length))];
  2660.                     randomLength = rand.nextInt(length);
  2661.                     var newVine = vines[randomSide];
  2662.                     for (var extendVine = 0; extendVine <= randomLength; extendVine++) {
  2663.                         if (session.getBlockType(pos.add(0,-(extendVine),0)) == 0) {
  2664.                             if (mat.next(0,0,0).getType() == BlockID.VINE) {
  2665.                                 session.setBlock(pos.add(0,-(extendVine),0), newVine);
  2666.                             }
  2667.                             else {
  2668.                                 session.setBlock(pos.add(0,-(extendVine),0), mat);
  2669.                             }
  2670.                             continue;
  2671.                         }
  2672.                         break;
  2673.                     }
  2674.                 }
  2675.             }
  2676.         }
  2677.     }  
  2678. }
  2679.  
  2680. function BuildLine(vec, session)    {
  2681.  
  2682.     var lineMode = checkFlag("m") ? parseInt(checkFlag("m")) : 1;
  2683.     var size = checkFlag("s") ? parseInt(checkFlag("s")) : 1;
  2684.     var block = checkFlag("b") ? parseBlock(checkFlag("b")) :  new BaseBlock(1);
  2685.     var extendCnt = checkFlag("e") ? parseInt(checkFlag("e")) :  0;
  2686.     var mat = (gMat == airMat) ? new SingleBlockPattern(block) : gMat;
  2687.     size = gSize != -1 ? gSize : size; 
  2688.    
  2689.     var baseVec = zVec;
  2690.  
  2691.     if (stage == 0) {
  2692.         player.print(text.White + text.Italics + "Origin set!");
  2693.         gVec = vec;
  2694.         stage++;
  2695.         return;
  2696.     }
  2697.    
  2698.     switch(lineMode)    {   //lineMode - 0 = Single Line; 1 = Continous; 2 = Fixed Origin.
  2699.  
  2700.     case 0:
  2701.        
  2702.         if (stage == 1) {
  2703.             baseVec = gVec;
  2704.             stage++;
  2705.         }
  2706.         else    {
  2707.             gVec = vec;
  2708.             player.print(text.White + text.Italics + "Origin set!");
  2709.             stage--;
  2710.         }
  2711.         break;
  2712.     case 1:
  2713.         baseVec = gVec;
  2714.         gVec = vec;
  2715.         break;
  2716.     case 2:
  2717.         baseVec = gVec;
  2718.         break;                 
  2719.     }
  2720.  
  2721.     if((lineMode == 1) || (lineMode == 2) || (stage == 2))  {
  2722.    
  2723.         var distance = getDistance(baseVec, vec);
  2724.         var step = .9/distance;
  2725.         var extendBase = (extendCnt * step);
  2726.        
  2727.         for(var i = 0; i <= (1 + extendBase); i += step) {
  2728.                
  2729.             var xi = vec.getX() + ((baseVec.getX() - vec.getX()) * i);
  2730.             var yi = vec.getY() + ((baseVec.getY() - vec.getY()) * i);
  2731.             var zi = vec.getZ() + ((baseVec.getZ() - vec.getZ()) * i);
  2732.             var pos = new Vector(xi, yi, zi);
  2733.  
  2734.             if (size == 0)  {
  2735.                 session.setBlock(pos, mat );
  2736.             }
  2737.             else    {
  2738.                 CreateSphere(size, 1, pos, mat, session);
  2739.             }
  2740.         }
  2741.     }
  2742.    
  2743. }
  2744.  
  2745. function BuildPlatform(vec, session){
  2746.    
  2747.     var size = checkFlag("s") ? parseInt(checkFlag("s")) : 3;
  2748.     var block = checkFlag("b") ? parseBlock(checkFlag("b")) :  new BaseBlock(20);
  2749.     var mat = (gMat == airMat) ? new SingleBlockPattern(block) : gMat;
  2750.     size = gSize != -1 ? gSize : size; 
  2751.    
  2752.     vec = player.getBlockIn();
  2753.     vec = vec.add(0,-1,0);
  2754.    
  2755.     for (var x = 0; x <= size; x++) {
  2756.         for (var z = 0; z <= size; z++) {
  2757.            
  2758.             pos = vec.add(x - size/2 + .5, 0, z - size/2 + .5);
  2759.             distance = getDistance(vec, pos);
  2760.            
  2761.             if (distance > size/2)  {continue;}
  2762.             session.setBlock(pos, mat);
  2763.         }
  2764.     }
  2765. }
  2766.  
  2767. function BuildBiome(vec, session)   {
  2768.    
  2769.     if (argv.length < 3)    {
  2770.         player.print (text.Red + "Error:" + text.White + " You need to specify a biome type to use.");
  2771.         return false;
  2772.     }
  2773.    
  2774.     var we = getWorldEdit();
  2775.     if (we == false)    {return false;}
  2776.    
  2777.     var biome = String(argv[2]).toUpperCase();
  2778.     var size = checkFlag("#") ? parseInt(checkFlag("#")) : 7;
  2779.     size = gSize != -1 ? gSize : size;
  2780.  
  2781.     var biomeList = String(we.getServer().getBiomes().all());
  2782.    
  2783.     try{
  2784.         target = BiomeType(we.getServer().getBiomes().get(biome));
  2785.     }
  2786.     catch (e)   {
  2787.         player.print("\n" + text.Red + "Error: " + text.White + "Biome type " + text.Red + biome.toLowerCase() + text.White + " not found.");
  2788.         player.print(text.Gold + text.Italics + "Available Biome Types: \n" + text.White + biomeList);
  2789.         return false;
  2790.     }
  2791.    
  2792.     if (vecList.length < 1) {
  2793.         player.print(text.Gold + biome + text.White + " biome found.");
  2794.         return;
  2795.     }
  2796.        
  2797.     for (var x = 0; x <= size; x++) {
  2798.         for (var z = 0; z <= size; z++) {
  2799.            
  2800.             pos = vec.add(x - size/2 + .5, 0, z - size/2 + .5);
  2801.             distance = getDistance(vec, pos);
  2802.            
  2803.             if (distance > size/2)  {continue;}
  2804.            
  2805.             player.getWorld().setBiome(Vector2D(pos.getX(),pos.getZ()), target);
  2806.             var yMax = session.getHighestTerrainBlock(pos.getX(),pos.getZ(), 0, 256, false);
  2807.         }
  2808.     }
  2809.     session.simulateSnow(vec, size/2);
  2810.     generateError();
  2811. }
  2812.  
  2813. function BuildMirror(vec, session)  {
  2814.    
  2815.     var world = context.getSession().getSelectionWorld();
  2816.     var region = context.getSession().getSelection(world);
  2817.    
  2818.     var pos = region.getMinimumPoint();
  2819.     var width = region.getWidth();
  2820.     var length = region.getLength();
  2821.     var height = region.getHeight();
  2822.     var vec2 =  player.getBlockIn();
  2823.     var dirInfo = getDirection();  
  2824.  
  2825.     if ((dirInfo.rightAngle == 0) || (dirInfo.rightAngle == 180))   {
  2826.         var offDir = pos.getX()-vec.getX();
  2827.  
  2828.         for (x = 0; x < width; x++)     {
  2829.             for (y = 0; y < height; y++)        {
  2830.                 for (z = 0; z < length; z++)        {
  2831.  
  2832.                     var tmpVec = pos.add(x, y, z);
  2833.                     var offLen = (offDir + x);
  2834.                     var newVec = tmpVec.add(-(offLen*2),0,0);
  2835.                     var tmpBlock = session.getBlock(tmpVec);
  2836.                     tmpBlock.flip(CuboidClipboard.FlipDirection.NORTH_SOUTH);
  2837.                    
  2838.                     if (checkFlag("d")) {
  2839.                         session.setBlock(tmpVec, airMat);
  2840.                     }  
  2841.                     session.setBlock(newVec, tmpBlock);
  2842.                    
  2843.                     if (checkFlag("s")) {
  2844.                         if((x == 0) && (y == 0) && (z == 0))    {
  2845.                             var selector = context.getSession().getRegionSelector(player.getWorld());
  2846.                             if (selector.selectPrimary(newVec)) {
  2847.                                 context.getSession().dispatchCUISelection(player);
  2848.                             }
  2849.                         }
  2850.                         if((x == (width-1)) && (y == (height-1)) && (z == (length-1)))  {
  2851.                             var selector = context.getSession().getRegionSelector(player.getWorld());
  2852.                             if (selector.selectSecondary(newVec)) {
  2853.                                 context.getSession().dispatchCUISelection(player);
  2854.                             }
  2855.                         }
  2856.                     }
  2857.                 }
  2858.             }
  2859.         }
  2860.     }
  2861.    
  2862.     if ((dirInfo.rightAngle == 90) || (dirInfo.rightAngle == 270))  {
  2863.         var offDir = pos.getZ()-vec.getZ();
  2864.  
  2865.         for (x = 0; x < width; x++)     {
  2866.             for (y = 0; y < height; y++)        {
  2867.                 for (z = 0; z < length; z++)        {
  2868.    
  2869.                     var tmpVec = pos.add(x, y, z);
  2870.                     var offLen = (offDir + z);
  2871.                     var newVec = tmpVec.add(0,0,-(offLen*2));
  2872.                     var tmpBlock = session.getBlock(tmpVec);
  2873.                    
  2874.                     tmpBlock.flip(CuboidClipboard.FlipDirection.WEST_EAST);
  2875.                    
  2876.                     if (checkFlag("d")) {
  2877.                         session.setBlock(tmpVec, airMat);
  2878.                     }
  2879.                     session.setBlock(newVec, tmpBlock);
  2880.    
  2881.                     if (checkFlag("s")) {
  2882.                         if((x == 0) && (y == 0) & (z == 0)) {
  2883.                             var selector = context.getSession().getRegionSelector(player.getWorld());
  2884.                             if (selector.selectPrimary(newVec)) {
  2885.                                 context.getSession().dispatchCUISelection(player);
  2886.                             }
  2887.                         }
  2888.                         if((x == (width-1)) && (y == (height-1)) && (z == (length-1)))  {
  2889.                             var selector = context.getSession().getRegionSelector(player.getWorld());
  2890.                             if (selector.selectSecondary(newVec)) {
  2891.                                 context.getSession().dispatchCUISelection(player);
  2892.                             }
  2893.                         }
  2894.                     }
  2895.                 }
  2896.             }
  2897.         }
  2898.     }
  2899.    
  2900.  
  2901. }
  2902.  
  2903. function BuildLaser(vec, session)   {
  2904.  
  2905.     var size = checkFlag("s") ? parseInt(checkFlag("s")) : 1;
  2906.     var depth = checkFlag("d") ? parseInt(checkFlag("d")) :  0;
  2907.     var blockA = checkFlag("a") ? parseBlock(checkFlag("a")) :  new BaseBlock(1);
  2908.     var matB = checkFlag("b") ? parseBlock(checkFlag("b")) :  new BaseBlock(1);
  2909.     var matA = (gMat == airMat) ? new SingleBlockPattern(blockA) : gMat;
  2910.     size = gSize != -1 ? gSize : size;
  2911.  
  2912.     var origin = player.getBlockIn().add(0,1,0);
  2913.     var distance = getDistance(origin, vec);
  2914.     var step = .9/distance;
  2915.     var extendBeam = 1 + (depth*step);
  2916.    
  2917.     for( var i = 0; i <= extendBeam; i += step) {
  2918.        
  2919.         if (i < ((size*step) + step*2)) {continue;}
  2920.        
  2921.         var xi = origin.getX() + ((vec.getX() - origin.getX()) * i);
  2922.         var yi = origin.getY() + ((vec.getY() - origin.getY()) * i);
  2923.         var zi = origin.getZ() + ((vec.getZ() - origin.getZ()) * i);
  2924.         var pos = new Vector(xi, yi, zi);
  2925.        
  2926.         if (i <= 1) {
  2927.             if (size == 1)  {
  2928.                 session.setBlock(pos, matA);
  2929.             }
  2930.             else    {
  2931.                 CreateSphere(size, 1, pos, matA, session);
  2932.             }      
  2933.         }
  2934.         else if (i > 1) {
  2935.             if (size == 1)  {
  2936.                 session.setBlock(pos, matB);
  2937.             }
  2938.             else    {
  2939.                 CreateSphere(size, 1, pos, matB, session);
  2940.             }
  2941.         }
  2942.  
  2943.     }
  2944. }
  2945.    
  2946. function BuildRevolve(vec, session) {
  2947.  
  2948.     var pointOver = checkFlag("c") ? parseInt(checkFlag("c")) : 0;
  2949.     var bTypeB = checkFlag("b") ? parseBlock(checkFlag("b")) :  new BaseBlock(0);
  2950.  
  2951.     var world = context.getSession().getSelectionWorld();
  2952.     var region = context.getSession().getSelection(world);
  2953.  
  2954.     var regionMin = new Vector(region.getMinimumPoint().getX(), region.getMinimumPoint().getY(), region.getMinimumPoint().getZ());
  2955.     var bTypeA = new BaseBlock(0);
  2956.  
  2957.     var pointRes = 16;
  2958.  
  2959.     for (var x = 0; x < region.getWidth(); x++ ) {
  2960.         for (var y = 0; y < region.getHeight(); y++ ) {
  2961.             for (var z = 0; z < region.getLength(); z++) {
  2962.                
  2963.                 var pos = regionMin.add(x, y, z);
  2964.                 var id = session.getBlock(pos);
  2965.                 var bCheck = 0;
  2966.                 if (bTypeB.getType() != 0) {bCheck = id.getType() != bTypeB.getType() ? 1 : 0};    
  2967.                                                                                                    
  2968.                 if (((id.getType()) != (bTypeA.getType())) && (bCheck == 0))       
  2969.                 {          
  2970.                     var radZ = Math.abs(vec.getZ()-pos.getZ());
  2971.                     var radX = Math.abs(vec.getX()-pos.getX());
  2972.                     var radius = radX > radZ ? radX : radZ;
  2973.                    
  2974.                     var points = pointOver != 0 ? pointOver : (pointRes * radius);
  2975.                     var slice = 2 * Math.PI / points;
  2976.                    
  2977.                     for (var i = 0; i < (points); i++)
  2978.                     {
  2979.                         var angle = (slice * i);
  2980.                         var newX = (radius * Math.cos(angle));
  2981.                         var newY = (radius * Math.sin(angle));
  2982.                         var newZ = (pos.getY() - vec.getY());
  2983.                         var pt = vec.add(newX, newZ, newY);
  2984.  
  2985.                         session.setBlock(pt, id);
  2986.                     }
  2987.                 }          
  2988.             }
  2989.         }
  2990.     }
  2991. }
  2992.  
  2993. function BuildRotate(vec, session)  {
  2994.    
  2995.     var angleArg = checkFlag("i") ? parseInt(checkFlag("i")) : 8;
  2996.     var resolution = checkFlag("r") ? parseInt(checkFlag("r")) : 4;
  2997.     var singleMode = checkFlag("s") ? true : false;
  2998.  
  2999.     var world = context.getSession().getSelectionWorld();
  3000.     var region = context.getSession().getSelection(world);
  3001.  
  3002.     angleArg = angleArg == 0 ? 8 : angleArg;
  3003.     angleStep = angleArg < 0 ? Math.abs(angleArg) : (360/angleArg);
  3004.  
  3005.     var step = 1 / resolution;
  3006.    
  3007.     for (var x = 0; x < region.getWidth(); x += step) {
  3008.         for (var z = 0; z < region.getLength(); z += step) {
  3009.             for (var y = 0; y < region.getHeight(); y += 1) {
  3010.                
  3011.                 var tmpVec = region.getMinimumPoint().add(x, y, z);
  3012.                
  3013.                 var block = session.getBlock(tmpVec);
  3014.                 if (block.getType() == BlockID.AIR) {continue;}
  3015.                
  3016.                 var angle = angleStep;             
  3017.                 while (angle < 360) {
  3018.                    
  3019.                     var newVec = Vector(rotateVec(vec, tmpVec, angle));
  3020.                     var oldVec = Vector(rotateVec(vec, newVec, -angle));
  3021.                    
  3022.                     if (session.getBlock(oldVec).getType() == block.getType() && session.getBlock(newVec).getType() != block.getType()) {
  3023.  
  3024.                         session.setBlock(newVec, block);
  3025.                     }
  3026.                    
  3027.                     if (singleMode) {angle = 360;}
  3028.                     angle += angleStep;
  3029.                 }  
  3030.             }
  3031.         }
  3032.     }
  3033. }
  3034.  
  3035. function BuildErode(vec, session)   {
  3036.  
  3037.     var size = checkFlag("s") ? parseInt(checkFlag("s")) : 8;
  3038.     var maxFaces = checkFlag("f") ? parseInt(checkFlag("f")) :  3;
  3039.     var strength = checkFlag("i") ? parseInt(checkFlag("i")) :  1;
  3040.     size = gSize != -1 ? gSize : size; 
  3041.     maxFaces = (gMat == airMat) ? maxFaces : gMat.next(zVec).getType();
  3042.    
  3043.     if (size == 0)  {size = 4;}
  3044.     var blocks = [];
  3045.    
  3046.     for (iteration = 1; iteration <= strength; iteration++) {
  3047.        
  3048.         var blockTotal = 0;        
  3049.         var blockCnt = 0;          
  3050.         var blockFaces = new Array(6);
  3051.        
  3052.         for (var x = 0; x <= size; x++) {
  3053.             for (var y = 0; y <= size; y++) {
  3054.                 for (var z = 0; z <= size; z++) {                  
  3055.                     pos = vec.add(x - size/2 + .5, y - size/2 + .5, z - size/2 + .5);
  3056.                     distance = getDistance(vec, pos);
  3057.                     if (distance > size/2)  {continue;}
  3058.                    
  3059.                     var curBlock = session.getBlock(pos);
  3060.                    
  3061.                     var blockCnt = 0;
  3062.                     var blockFaces = [];
  3063.                    
  3064.                     blockFaces[1] = session.getBlockType(pos.add(1,0,0));
  3065.                     blockFaces[2] = session.getBlockType(pos.add(-1,0,0));
  3066.                     blockFaces[3] = session.getBlockType(pos.add(0,1,0));
  3067.                     blockFaces[4] = session.getBlockType(pos.add(0,-1,0));
  3068.                     blockFaces[5] = session.getBlockType(pos.add(0,0,1));
  3069.                     blockFaces[6] = session.getBlockType(pos.add(0,0,-1)); 
  3070.                    
  3071.                     for (var inc = 1; inc <= 6; inc++) {
  3072.                         if((blockFaces[inc]) == 0) {blockCnt++;}                                               
  3073.                     }
  3074.                    
  3075.                     if (blockCnt >= maxFaces) {
  3076.                         blocks[blockTotal] = BlockID.AIR;
  3077.                     }
  3078.                     else {
  3079.                         blocks[blockTotal] = curBlock.getType();
  3080.                     }
  3081.                     blockTotal++;
  3082.  
  3083.                 }
  3084.             }
  3085.         }
  3086.        
  3087.         var setBlockTotal = 0;
  3088.         for (var x = 0; x <= size; x++) {
  3089.             for (var y = 0; y <= size; y++) {
  3090.                 for (var z = 0; z <= size; z++) {              
  3091.                     pos = vec.add(x - size/2 + .5, y - size/2 + .5, z - size/2 + .5);
  3092.                     distance = getDistance(vec, pos);
  3093.                     if (distance > size/2)  {continue;}
  3094.                    
  3095.                     var ID = blocks[setBlockTotal];
  3096.  
  3097.                     session.setBlock(pos, new BaseBlock(ID));
  3098.                     setBlockTotal++;
  3099.  
  3100.                 }
  3101.             }
  3102.         }
  3103.     }
  3104.  
  3105. }
  3106.  
  3107. function BuildFill(vec, session)    {
  3108.  
  3109.     var size = checkFlag("s") ? parseInt(checkFlag("s")) : 8;
  3110.     var maxFaces = checkFlag("f") ? parseInt(checkFlag("f")) :  3;
  3111.     var strength = checkFlag("i") ? parseInt(checkFlag("i")) :  1;
  3112.     size = gSize != -1 ? gSize : size; 
  3113.     maxFaces = (gMat == airMat) ? maxFaces : gMat.next(zVec).getType();
  3114.    
  3115.     if (size == 0)  {size = 4;}
  3116.     var blocks = [];
  3117.    
  3118.     for (iteration = 1; iteration <= strength; iteration++) {
  3119.        
  3120.         var blockTotal = 0;        
  3121.         var blockCnt = 0;          
  3122.         var blockFaces = new Array(6);
  3123.        
  3124.         for (var x = 0; x <= size; x++) {
  3125.             for (var y = 0; y <= size; y++) {
  3126.                 for (var z = 0; z <= size; z++) {                  
  3127.                     pos = vec.add(x - size/2 + .5, y - size/2 + .5, z - size/2 + .5);
  3128.                     distance = getDistance(vec, pos);
  3129.                     if (distance > size/2)  {continue;}
  3130.                    
  3131.                     var curBlock = session.getBlock(pos);
  3132.                     if (curBlock.getType() != BlockID.AIR) {
  3133.                         blocks[blockTotal] = curBlock.getType();
  3134.                         blockTotal++;
  3135.                         continue;
  3136.                     }
  3137.                    
  3138.                     var blockCnt = 0;
  3139.                     var blockFaces = [];
  3140.                    
  3141.                     blockFaces[1] = session.getBlockType(pos.add(1,0,0));
  3142.                     blockFaces[2] = session.getBlockType(pos.add(-1,0,0));
  3143.                     blockFaces[3] = session.getBlockType(pos.add(0,1,0));
  3144.                     blockFaces[4] = session.getBlockType(pos.add(0,-1,0));
  3145.                     blockFaces[5] = session.getBlockType(pos.add(0,0,1));
  3146.                     blockFaces[6] = session.getBlockType(pos.add(0,0,-1)); 
  3147.                    
  3148.                     var newArray = compressArray(blockFaces);
  3149.                    
  3150.                     var maxFace = new Object()
  3151.                    
  3152.                     for (var lpC = 1; lpC <= 6; lpC++) {
  3153.                        
  3154.                         if(blockFaces[lpC] != 0) {blockCnt++;}                                             
  3155.                     }
  3156.                    
  3157.                     for (q in newArray) {
  3158.                         if (newArray[q].value != 0) {
  3159.                             if (typeof maxFace.value === "undefined") {
  3160.                                 maxFace = newArray[q];
  3161.                             }                          
  3162.                             if (newArray[q].count > maxFace.count) {
  3163.                                 maxFace = newArray[q];
  3164.                             }
  3165.                         }
  3166.                     }
  3167.                        
  3168.                     if (blockCnt >= maxFaces){
  3169.                         if (typeof maxFace.value === "undefined") {
  3170.                             blocks[blockTotal] = BlockID.STONE
  3171.                         }
  3172.                         else {
  3173.                             blocks[blockTotal] = maxFace.value
  3174.                         }
  3175.                     }  
  3176.                     else {
  3177.                         blocks[blockTotal] = curBlock.getType();
  3178.                     }
  3179.                     blockTotal++;
  3180.  
  3181.                 }
  3182.             }
  3183.         }
  3184.        
  3185.         var setBlockTotal = 0;
  3186.         for (var x = 0; x <= size; x++) {
  3187.             for (var y = 0; y <= size; y++) {
  3188.                 for (var z = 0; z <= size; z++) {              
  3189.                     pos = vec.add(x - size/2 + .5, y - size/2 + .5, z - size/2 + .5);
  3190.                     distance = getDistance(vec, pos);
  3191.                     if (distance > size/2)  {continue;}
  3192.                    
  3193.                     var ID = blocks[setBlockTotal];
  3194.  
  3195.                     session.setBlock(pos, new BaseBlock(ID));
  3196.                     setBlockTotal++;
  3197.  
  3198.                 }
  3199.             }
  3200.         }
  3201.     }
  3202.  
  3203.  
  3204.  
  3205. }
  3206.  
  3207. function BuildWand(vec, session)    {
  3208.    
  3209.     var wandTool = new DoubleActionTraceTool({
  3210.         canUse : function(player) {
  3211.             return player.hasPermission("worldedit.tool.wand");
  3212.         },
  3213.         actPrimary : function(server,config,player,session) {
  3214.             var vec = player.getBlockIn()
  3215.             if (vec == null) { return; }
  3216.             var selector = session.getRegionSelector(player.getWorld());
  3217.             if (selector.selectSecondary(vec)) {
  3218.                 session.dispatchCUISelection(player);
  3219.             }
  3220.             return;
  3221.         },
  3222.         actSecondary : function(server,config,player,session) {
  3223.            
  3224.             var vec = checkFlag("~") ? player.getBlockTrace(parseInt(checkFlag("~")), true) : player.getBlockTrace(200, false);
  3225.             if (vec == null) { return; }
  3226.  
  3227.             var selector = session.getRegionSelector(player.getWorld());
  3228.             var setVec = selector.isDefined() ? selector.getPrimaryPosition(): zVec.toBlockVector();
  3229.            
  3230.             if (setVec.equals(vec.toBlockVector())) {
  3231.                 selector.clear();
  3232.                 session.dispatchCUISelection(player);
  3233.                 player.print(text.White + text.Italics + "Selection cleared.");
  3234.                 return;
  3235.             }
  3236.  
  3237.             if (selector.selectPrimary(vec)) {
  3238.                 session.dispatchCUISelection(player);
  3239.             }
  3240.             return;
  3241.  
  3242.         }, 
  3243.     });
  3244.    
  3245.     context.getSession().setTool(player.getItemInHand(), wandTool);
  3246.  
  3247. }
  3248.  
  3249. function BuildOre(vec, session)     {
  3250.  
  3251.     var size = checkFlag("s") ? parseInt(checkFlag("s")) : 20;
  3252.     var density = checkFlag("d") ? parseInt(checkFlag("d")) : 100;
  3253.     var overBlockID = checkFlag("b") ? parseBlock(checkFlag("b")).getType() :  BlockID.STONE;
  3254.     var origin = vec.add(0 - size/2 + .5, 0 - size/2 + .5, 0 - size/2 + .5);
  3255.  
  3256.     var width = size;
  3257.     var height = size;
  3258.     var length = size;
  3259.     var area = width * height * length;
  3260.    
  3261.     if(checkFlag("r"))  {
  3262.         var world = context.getSession().getSelectionWorld();
  3263.         var region = context.getSession().getSelection(world);
  3264.    
  3265.         var width = Math.abs(region.getMaximumPoint().getX() - region.getMinimumPoint().getX());
  3266.         var height = Math.abs(region.getMinimumPoint().getY() - region.getMaximumPoint().getY());
  3267.         var length = Math.abs(region.getMinimumPoint().getZ() - region.getMaximumPoint().getZ());
  3268.         var area = width * height * length;
  3269.         var origin = new Vector(
  3270.                 region.getMinimumPoint().getX(),
  3271.                 region.getMinimumPoint().getY(),
  3272.                 region.getMinimumPoint().getZ()
  3273.                 );
  3274.        
  3275.     }
  3276.    
  3277.     var oreTotal = 0;
  3278.     for (var oInc in oreList)   {
  3279.         oreTotal++;
  3280.     }
  3281.    
  3282.     var rand = new java.util.Random();  
  3283.     var densityStep = 300;
  3284.     var maxVeinSize = 12;
  3285.     var veinCount = 0;
  3286.     var oreCount = 0;
  3287.  
  3288.     var maxPoints = (area / densityStep) * (density / 100);
  3289.  
  3290.     for ( var pointStep = 0; pointStep < maxPoints; pointStep++) {
  3291.            
  3292.         randPnt = origin.add(rand.nextInt(width), rand.nextInt(height), rand.nextInt(length));
  3293.         randPnt2 = randPnt.add(rand.nextInt(maxVeinSize)*2-maxVeinSize, rand.nextInt(maxVeinSize)*2-maxVeinSize, rand.nextInt(maxVeinSize)*2-maxVeinSize);
  3294.  
  3295.         if (session.getBlock(randPnt).getType() != overBlockID) {continue;}
  3296.         var distance = getDistance(randPnt, randPnt2);
  3297.        
  3298.         var testOre = [];
  3299.         var maxOreID = 0;
  3300.         var maxOreChance = 0;
  3301.         var chanceMax = 0;
  3302.  
  3303.         for (var findOre = 1; findOre <= oreTotal; findOre++)   {
  3304.            
  3305.             if (randPnt.getY() <= 0)    { continue; }
  3306.            
  3307.             if ((oreList[findOre].minY <= randPnt.getY()) && (oreList[findOre].maxY >= randPnt.getY())) {
  3308.                
  3309.                 var tmpOre = new Object();
  3310.                 tmpOre.myOreID = findOre;
  3311.                
  3312.                 tmpOre.minChance = chanceMax;
  3313.                 tmpOre.maxChance = chanceMax + oreList[findOre].chance;
  3314.                 testOre.push(tmpOre);
  3315.                 chanceMax += oreList[findOre].chance;
  3316.             }
  3317.         }
  3318.        
  3319.         if(testOre.length <= 0) { continue; }
  3320.         randomProb = Math.random() * chanceMax;
  3321.  
  3322.         for (var getOre = 0; getOre < testOre.length; getOre++) {
  3323.             if ((randomProb >= testOre[getOre].minChance) && (randomProb <= testOre[getOre].maxChance)) {
  3324.                 maxOreID = testOre[getOre].myOreID;
  3325.             }
  3326.         }
  3327.        
  3328.         var bType = new BaseBlock(oreList[maxOreID].BlockID);
  3329.        
  3330.         var step = .9/distance;
  3331.         var newLength = (rand.nextInt(oreList[maxOreID].maxSize - oreList[maxOreID].minSize) + oreList[maxOreID].minSize);
  3332.         var chgCount = 0;
  3333.        
  3334.         for( var i = 0; i <= 1; i += step ) {
  3335.            
  3336.             if (chgCount >= newLength)  {break;}
  3337.            
  3338.             var distance = getDistance(randPnt, randPnt2);
  3339.             var step = .9/distance;
  3340.  
  3341.             for( var i = 0; i <= 1; i += step) {
  3342.                    
  3343.                 var xi = randPnt.getX() + ((randPnt2.getX() - randPnt.getX()) * i);
  3344.                 var yi = randPnt.getY() + ((randPnt2.getY() - randPnt.getY()) * i);
  3345.                 var zi = randPnt.getZ() + ((randPnt2.getZ() - randPnt.getZ()) * i);
  3346.                                
  3347.                 var vecA = new Vector(xi, yi, zi);
  3348.                 if(vecA.getY() <= 0)    { continue; }
  3349.                
  3350.                 if (session.getBlock(vecA).getType() == overBlockID)    {
  3351.                     session.setBlock(vecA, bType); 
  3352.                     chgCount++;
  3353.                     oreCount++;
  3354.                 }
  3355.             }
  3356.            
  3357.            
  3358.         }
  3359.         veinCount++;
  3360.        
  3361.     }
  3362. }
  3363.  
  3364. function BuildFragment(vec, session)    {
  3365.    
  3366.     var size = checkFlag("s") ? parseInt(checkFlag("s")) : 7;
  3367.     var block = checkFlag("b") ? parseBlock(checkFlag("b")) : new BaseBlock(1);
  3368.     var density = checkFlag("d") ? parseFloat(checkFlag("d")) : .75;
  3369.     var hollow = checkFlag("h") ? parseInt(checkFlag("h")) : 0;
  3370.  
  3371.     size = gSize != -1 ? gSize + (gSize * Math.random()*.2) : size;
  3372.     var mat = (gMat == airMat) ? new SingleBlockPattern(block) : gMat; 
  3373.    
  3374.     CreateLeafSphere(size, size, density, hollow, vec.add(0,-(size/2),0), mat, session);
  3375.  
  3376. }
  3377.  
  3378. function BuildSpawner(vec, session) {
  3379.  
  3380.     var entityList = [
  3381.         "bat", "chicken", "cow", "pig", "sheep", "squid", "villager", "enderman", "pigzombie", "blaze",
  3382.         "creeper", "ghast", "silverfish", "wither", "slime", "lavaslime", "spider", "cavespider", "witch",
  3383.         "zombie", "ozelot", "wolf", "villagergolem", "snowman", "enderdragon", "witherboss", "giant", "boat",
  3384.         "minecart", "mushroomcow", "endercrystal", "item", "xporb", "arrow", "snowball", "fireball", "smallfireball"
  3385.     ]
  3386.  
  3387.     var type = argv.length > 2 ? String(argv[2]).toLowerCase() : "-";
  3388.     entityList.sort();
  3389.    
  3390.     for (inc in entityList) {
  3391.        
  3392.         if(type == "all")
  3393.             session.setBlock(vec.add(0,parseInt(inc)+1,0), MobSpawnerBlock(entityList[inc].toLowerCase()));
  3394.        
  3395.         if(entityList[inc].toLowerCase() == type)   {
  3396.             session.setBlock(vec.add(0,1,0), MobSpawnerBlock(entityList[inc].toLowerCase()));
  3397.             return;
  3398.         }
  3399.     }
  3400.    
  3401.     if (type != "all")  {
  3402.         player.print("\n" + text.Red + "Error: " + text.White + "Entity type " + text.Gold + type + text.White + " not found.");
  3403.         player.print(text.Gold + text.Italics + "Available Entity Types: \n" + text.White + "[" + entityList + "]");
  3404.     }  
  3405.  
  3406. }
  3407.  
  3408. function BuildKiller(vec, session)  {
  3409.  
  3410.     var entityType = argv.length > 2 ? String(argv[2]).toLowerCase() : false;
  3411.     var size = checkFlag("s") ? parseInt(checkFlag("s")) : 7;
  3412.     size = gSize != -1 ? gSize : size;
  3413.    
  3414.     var pos1 = Vector(vec.getX()-size/2, vec.getY()-size/2, vec.getZ()-size/2);
  3415.     var pos2 = Vector(vec.getX()+size/2, vec.getY()+size/2, vec.getZ()+size/2);
  3416.     var region = new CuboidRegion(pos1, pos2);
  3417.        
  3418.     /* Entity killing - unstable
  3419.    
  3420.     var entities = player.getWorld().getEntities(region);
  3421.     for (var entity in entities) {
  3422.         var tmp2 = entities[entity].getPosition().position;
  3423.         var tmp3 = entities[entity].getClass().getType();
  3424.         player.print("Entity Killed @ " + String(tmp2) + String(tmp3));
  3425.        
  3426.         for (sube in  entities[entity])
  3427.             //player.print(sube);
  3428.  
  3429.     }
  3430.     player.getWorld().killEntities(entities);
  3431.     */
  3432.    
  3433.     /* Entity Spawning
  3434.         public LocalEntity[] pasteEntities(Vector pos) {
  3435.         LocalEntity[] entities = new LocalEntity[this.entities.size()];
  3436.         for (int i = 0; i < this.entities.size(); ++i) {
  3437.             CopiedEntity copied = this.entities.get(i);
  3438.             if (copied.entity.spawn(copied.entity.getPosition().setPosition(copied.relativePosition.add(pos)))) {
  3439.                 entities[i] = copied.entity;
  3440.             }
  3441.         }
  3442.         return entities;
  3443.     }
  3444.    
  3445.    
  3446.     */
  3447.    
  3448.     /* Alt killing method - unstable
  3449.    
  3450.     var entities = player.getWorld().getWorld().getLivingEntities();
  3451.    
  3452.     var cnt = 0;
  3453.     for (var inc = 0; inc < entities.size(); inc++) {
  3454.         var entity = entities.get(inc);
  3455.         var type = String(entity.getType()).toLowerCase();
  3456.         var loc = entity.getLocation();
  3457.         var pos = new Vector(parseInt(loc.getX()), parseInt(loc.getY()), parseInt(loc.getZ()));
  3458.        
  3459.         //player.print("what the hell?!" + entity + type + pos);
  3460.         if (region.contains(pos))   {
  3461.             player.print("inside");
  3462.             if (!(entityType) || (type == entityType))  {
  3463.                 entity.remove();
  3464.             }
  3465.         }
  3466.         //player.print("any luck?");
  3467.        
  3468.     }
  3469.     */
  3470.  
  3471. }
  3472.  
  3473. function BuildPattern(vec, session) {
  3474.  
  3475.     if (argv.length < 3)    {
  3476.         player.print (text.Red + "Error:" + text.White + " You need to specify a pattern type to use.");
  3477.         return false;
  3478.     }
  3479.  
  3480.     var blockList = String(argv[2]).toLowerCase();
  3481.     var size = checkFlag("s") ? parseInt(checkFlag("s")) : 10;
  3482.     blockList = blockList == "-" ? "ruin" : blockList;
  3483.     size = gSize != -1 ? gSize : size;
  3484.    
  3485.     if (blocks[blockList] == undefined) {
  3486.         player.print(text.Red + "Error:" + text.White + " Pattern type " + text.Gold + blockList + text.White + " not found.");
  3487.         return;
  3488.     }
  3489.    
  3490.     var blackList = [0,6,31,32,37,38,39,40,81,106];
  3491.    
  3492.     for (var x = 0; x <= size; x++) {
  3493.         for (var y = 0; y <= size; y++) {
  3494.             for (var z = 0; z <= size; z++) {                  
  3495.                 pos = vec.add(x - size/2 + .5, y - size/2 + .5, z - size/2 + .5);
  3496.                 distance = getDistance(vec, pos);
  3497.  
  3498.                 if (distance > size/2)  {continue;}
  3499.                
  3500.                 if (blackList.indexOf(session.getBlock(pos).getType()) != -1)   {continue;}
  3501.                    
  3502.                 session.setBlock(pos, getListBlock(blocks[blockList].list));
  3503.                 //session.setBlock(pos, getListBlock(blocks["Plants"].list));
  3504.  
  3505.  
  3506.             }
  3507.         }
  3508.     }
  3509.  
  3510. }
  3511.  
  3512. function BuildArray(vec, session)   {
  3513.  
  3514.     var world = context.getSession().getSelectionWorld();
  3515.     var region = context.getSession().getSelection(world);
  3516.  
  3517.     var cnt1 = checkFlag("a") ? parseInt(checkFlag("a")) : 0;
  3518.     var cnt2 = checkFlag("b") ? parseInt(checkFlag("b")) : 0;
  3519.     var cnt3 = checkFlag("c") ? parseInt(checkFlag("c")) : 0;
  3520.  
  3521.     var copyAir = false;
  3522.  
  3523.     switch(stage)   {
  3524.  
  3525.         case 0:
  3526.         case 1:
  3527.             offsetVec[0] = vec;
  3528.             offsetVec[1] = vec;
  3529.             offsetVec[2] = vec;
  3530.             offsetVec[3] = vec;
  3531.             player.print(text.White + "Origin point #1 set to [" + vec.getX() + ", " + vec.getY() + ", " + vec.getZ() + "]");
  3532.             player.print(text.Gold + text.Italics + "Ready for offset point #1.");
  3533.             stage = 2;
  3534.             break;
  3535.            
  3536.         case 2:
  3537.             offsetVec[1] = vec.add(-(offsetVec[0].getX()), -(offsetVec[0].getY()), -(offsetVec[0].getZ()));
  3538.             var pStr1 = (text.White + "Offset point #1 set to [" + vec.getX() + ", " + vec.getY() + ", " + vec.getZ() + "]\n")
  3539.             var pStr2 = (text.White + "Point #1 Offset Total: [" + offsetVec[1].getX() + ", " + offsetVec[1].getY() + ", " + offsetVec[1].getZ() + "]")
  3540.             player.print(pStr1 + pStr2);
  3541.             if (cnt2 == 0)  {
  3542.                 stage = 7;
  3543.                 break;
  3544.             }
  3545.             player.print(text.Gold + text.Italics + "Ready for origin point #2.");
  3546.             stage++;
  3547.             break;             
  3548.         case 3:
  3549.             offsetVec[0] = vec;
  3550.             player.print(text.White + "Origin point #2 set to [" + vec.getX() + ", " + vec.getY() + ", " + vec.getZ() + "]");
  3551.             player.print(text.Gold + text.Italics + "Ready for offset point #2.");
  3552.             stage++;
  3553.             break;     
  3554.  
  3555.         case 4:
  3556.             offsetVec[2] = vec.add(-(offsetVec[0].getX()), -(offsetVec[0].getY()), -(offsetVec[0].getZ()));
  3557.             var pStr1 = (text.White + "Offset point #2 set to [" + vec.getX() + ", " + vec.getY() + ", " + vec.getZ() + "]\n")
  3558.             var pStr2 = (text.White + "Point #2 Offset Total: [" + offsetVec[2].getX() + ", " + offsetVec[2].getY() + ", " + offsetVec[2].getZ() + "]")
  3559.             player.print(pStr1 + pStr2);
  3560.             if (cnt3 == 0)  {
  3561.                 stage = 7;
  3562.                 break;
  3563.             }
  3564.             player.print(text.Gold + text.Italics + "Ready for origin point #3.");
  3565.             stage++;
  3566.             break;             
  3567.         case 5:
  3568.             offsetVec[0] = vec;
  3569.             player.print(text.White + "Origin point #3 set to [" + vec.getX() + ", " + vec.getY() + ", " + vec.getZ() + "]");
  3570.             player.print(text.Gold + text.Italics + "Ready for offset point #3.");
  3571.             stage++;
  3572.             break; 
  3573.  
  3574.         case 6:
  3575.             offsetVec[3] = vec.add(-(offsetVec[0].getX()), -(offsetVec[0].getY()), -(offsetVec[0].getZ()));
  3576.             var pStr1 = (text.White + "Offset point #3 set to [" + vec.getX() + ", " + vec.getY() + ", " + vec.getZ() + "]\n")
  3577.             var pStr2 = (text.White + "Point #3 Offset Total: [" + offsetVec[3].getX() + ", " + offsetVec[3].getY() + ", " + offsetVec[3].getZ() + "]")
  3578.             player.print(pStr1 + pStr2);
  3579.             stage++;
  3580.             break;
  3581.     }
  3582.  
  3583.     if (stage == 10)    {
  3584.    
  3585.         var min = region.getMinimumPoint();
  3586.         var max = region.getMaximumPoint();
  3587.  
  3588.         var minX = min.getBlockX();
  3589.         var minY = min.getBlockY();
  3590.         var minZ = min.getBlockZ();
  3591.         var maxX = max.getBlockX();
  3592.         var maxY = max.getBlockY();
  3593.         var maxZ = max.getBlockZ();
  3594.        
  3595.         var setPos = new Vector;
  3596.         var setPos2 = new Vector;
  3597.        
  3598.         for (var x = minX; x <= maxX; ++x) {
  3599.             for (var z = minZ; z <= maxZ; ++z) {
  3600.                 for (var y = minY; y <= maxY; ++y) {
  3601.                
  3602.                     var block = session.getBlock(new Vector(x, y, z));
  3603.                     if (!block.isAir() || copyAir) {
  3604.                         for (var i = 0; i <= cnt1; ++i) {
  3605.                             setPos = Vector(x + offsetVec[1].getX() * i, y + offsetVec[1].getY() * i, z + offsetVec[1].getZ() * i);
  3606.  
  3607.                             for (var j = 0; j <= cnt2; ++j) {
  3608.                                 setPos2 = Vector(setPos.add(offsetVec[2].getX() * j, offsetVec[2].getY() * j, offsetVec[2].getZ() * j));
  3609.                                 for (var k = 0; k <= cnt3; ++k) {
  3610.                                     setPos3 = Vector(setPos2.add(offsetVec[3].getX() * k, offsetVec[3].getY() * k, offsetVec[3].getZ() * k));
  3611.                                
  3612.                                     session.setBlock(setPos3, block);
  3613.                                 }
  3614.                                 session.setBlock(setPos2, block);
  3615.                             }
  3616.                         }
  3617.                     }
  3618.                 }
  3619.             }
  3620.         }
  3621.         player.print(text.White + "Array complete!");
  3622.         stage = 0;
  3623.     }
  3624.    
  3625.     if (stage == 7) {
  3626.         player.print(text.Gold + text.Italics + "Everything is set!" + text.White + text.Italics + " Click once more to perform the array stack!");
  3627.         stage = 10;
  3628.     }
  3629.  
  3630. }
  3631.  
  3632. function BuildMap(vec, session) {
  3633.  
  3634.     if (argv.length > 2)    {
  3635.         var fileStr = String(argv[2]).toLowerCase();
  3636.     }
  3637.     else {      //no file specified
  3638.         player.print(text.Red + "Error: " + text.White + "You must specify a filename to save to.");
  3639.         return false;
  3640.     }
  3641.  
  3642.     var size = checkFlag("s", 3) ? parseInt(checkFlag("s")) : 256;
  3643.     var img = new BufferedImage(size, size, BufferedImage.TYPE_INT_RGB);
  3644.     var file = context.getSafeFile("shapes", String(fileStr) + '.png');
  3645.  
  3646.     if(!file.exists()){
  3647.         file.createNewFile();
  3648.     }
  3649.    
  3650.     blockColors = {         //RGB values for blocks
  3651.         1: Vector(85,85,85),        //stone
  3652.         2: Vector(0,225,0),         //grass
  3653.         9: Vector(0,0,255),         //water
  3654.         12: Vector(228,216,174),    //sand
  3655.         13: Vector(120,120,120),    //gravel
  3656.         17: Vector(165,103,53),     //wood
  3657.         18: Vector(76,150,24),      //leaves
  3658.         31: Vector(0,170,0),        //long grass
  3659.         37: Vector(255,248,56),     //yellow flower
  3660.         78: Vector(230,255,255),    //snow layer
  3661.         79: Vector(145,255,227),    //ice
  3662.         106: Vector(25,70,5),       //vines
  3663.     }
  3664.    
  3665.     vec = player.getBlockIn();
  3666.  
  3667.     for (var x = 0; x < size; x++) {
  3668.         for (var z = 0; z < size; z++) {
  3669.        
  3670.             pos = vec.add(x - size/2 + .5, 0, z - size/2 + .5);
  3671.             var yMax = session.getHighestTerrainBlock(pos.getX(),pos.getZ(), 0, 256, false);
  3672.  
  3673.             for (var y = yMax; y < 256; y++) {
  3674.                
  3675.                 var topVec = Vector(pos.getX(), y, pos.getZ());
  3676.                 if(session.getBlockType(topVec.add(0,1,0)) == 0)    {
  3677.                     var topID = session.getBlockType(topVec);
  3678.                     break;
  3679.                 }
  3680.             }
  3681.            
  3682.            
  3683.             clr = getColor(0,0,0);
  3684.             if (checkFlag("h", 3) == false) {
  3685.                 for(inc in blockColors) {
  3686.                     if(inc == topID)    {
  3687.                         clr = getColor(blockColors[inc].getX(), blockColors[inc].getY(), blockColors[inc].getZ());
  3688.                         break
  3689.                     }
  3690.                 }
  3691.             }
  3692.             else    {
  3693.                 var modb = 1;
  3694.                 for(inc in blockColors) {
  3695.                     if(inc == topID)    {
  3696.                         r = blockColors[inc].getX()-(y/modb) < 0 ? 0 : blockColors[inc].getX()-(y/modb);
  3697.                         g = blockColors[inc].getY()-(y/modb) < 0 ? 0 : blockColors[inc].getY()-(y/modb);
  3698.                         b = blockColors[inc].getZ()-(y/modb) < 0 ? 0 : blockColors[inc].getZ()-(y/modb);
  3699.                         clr = getColor(r, g, b);
  3700.                         break
  3701.                     }
  3702.                 }
  3703.                 //clr = getColor(y,y,y);
  3704.             }
  3705.            
  3706.            
  3707.            
  3708.             img.setRGB(x, z, clr);
  3709.         }      
  3710.     }
  3711.    
  3712.     ImageIO.write(img, "png", file);
  3713.     player.print(text.White + "Map image successfully saved to:\n" + text.Gold + file);
  3714.  
  3715. }
  3716.  
  3717. function BuildFlip(vec, session)    {
  3718.  
  3719.     var world = context.getSession().getSelectionWorld();
  3720.     var region = context.getSession().getSelection(world);
  3721.    
  3722.     var pos = region.getMinimumPoint();
  3723.     var width = region.getWidth();
  3724.     var length = region.getLength();
  3725.     var height = region.getHeight();
  3726.     var vec2 =  player.getBlockIn();
  3727.     var dirInfo = getDirection();  
  3728.  
  3729.     if ((dirInfo.rightAngle == 0) || (dirInfo.rightAngle == 180))   {
  3730.         var offDir = pos.getX()-vec.getX();
  3731.         for (x = 0; x < width; x++)     {
  3732.             for (y = 0; y < height; y++)        {
  3733.                 for (z = 0; z < length; z++)        {
  3734.                    
  3735.                     var tmpVec = pos.add(x,y,z);
  3736.                     var tmpBlock = session.getBlock(tmpVec);
  3737.                     var offLen = Math.abs(offDir + x);
  3738.                    
  3739.                     if ((tmpVec.getX()+width/2) <= vec.getX())
  3740.                         var newVec = Vector(vec.getX()+y,vec.getY()+offLen,pos.getZ()+z);
  3741.                     if ((tmpVec.getX()+width/2) > vec.getX())
  3742.                         var newVec = Vector(vec.getX()-y,vec.getY()+offLen,pos.getZ()+z);
  3743.                                    
  3744.                     if (checkFlag("d")) {
  3745.                         session.setBlock(tmpVec, airMat);
  3746.                     }                  
  3747.                     session.setBlock(newVec, tmpBlock);
  3748.                    
  3749.                     if (checkFlag("s")) {
  3750.                         if((x == 0) && (y == 0) & (z == 0)) {
  3751.                             var selector = context.getSession().getRegionSelector(player.getWorld());
  3752.                             if (selector.selectPrimary(newVec)) {
  3753.                                 context.getSession().dispatchCUISelection(player);
  3754.                             }
  3755.                         }
  3756.                         if((x == (width-1)) && (y == (height-1)) && (z == (length-1)))  {
  3757.                             var selector = context.getSession().getRegionSelector(player.getWorld());
  3758.                             if (selector.selectSecondary(newVec)) {
  3759.                                 context.getSession().dispatchCUISelection(player);
  3760.                             }
  3761.                         }
  3762.                     }
  3763.                 }
  3764.             }
  3765.         }
  3766.         return true;
  3767.     }
  3768.    
  3769.     if ((dirInfo.rightAngle == 90) || (dirInfo.rightAngle == 270))  {
  3770.         var offDir = pos.getZ()-vec.getZ();
  3771.         for (x = 0; x < width; x++)     {
  3772.             for (y = 0; y < height; y++)        {
  3773.                 for (z = 0; z < length; z++)        {
  3774.                
  3775.                     var tmpVec = pos.add(x,y,z);
  3776.                     var tmpBlock = session.getBlock(tmpVec);
  3777.                     var offLen = Math.abs(offDir + z);
  3778.                    
  3779.                     if ((pos.getZ()+length/2) <= vec.getZ())
  3780.                         var newVec = Vector(pos.getX()+x,vec.getY()+offLen,vec.getZ()+y);
  3781.                     if ((pos.getZ()+length/2) > vec.getZ())
  3782.                         var newVec = Vector(pos.getX()+x,vec.getY()+offLen,vec.getZ()-y);
  3783.                    
  3784.                    
  3785.                     //if(tmpBlock.getType() == BlockID.AIR) {continue} 
  3786.                     if (checkFlag("d")) {
  3787.                         session.setBlock(tmpVec, airMat);
  3788.                     }                  
  3789.                     session.setBlock(newVec, tmpBlock);
  3790.  
  3791.                     if (checkFlag("s")) {
  3792.                         if((x == 0) && (y == 0) & (z == 0)) {
  3793.                             var selector = context.getSession().getRegionSelector(player.getWorld());
  3794.                             if (selector.selectPrimary(newVec)) {
  3795.                                 context.getSession().dispatchCUISelection(player);
  3796.                             }
  3797.                         }
  3798.                         if((x == (width-1)) && (y == (height-1)) && (z == (length-1)))  {
  3799.                             var selector = context.getSession().getRegionSelector(player.getWorld());
  3800.                             if (selector.selectSecondary(newVec)) {
  3801.                                 context.getSession().dispatchCUISelection(player);
  3802.                             }
  3803.                         }
  3804.                     }
  3805.                 }
  3806.             }
  3807.         }
  3808.         return true;   
  3809.     }
  3810.  
  3811.  
  3812.  
  3813.  
  3814. }
  3815.  
  3816. function BuildBox(vec, session) {
  3817.  
  3818.     var xSize = checkFlag("x") ? parseInt(checkFlag("x")) : 20;
  3819.     var ySize = checkFlag("y") ? parseInt(checkFlag("y")) : 10;
  3820.     var zSize = checkFlag("z") ? parseInt(checkFlag("z")) : 5;
  3821.     var block = checkFlag("b") ? parseBlock(checkFlag("b")) :  new BaseBlock(20);
  3822.     var insideBlock = checkFlag("i") ? parseBlock(checkFlag("i")) :  false;
  3823.     var hollow = checkFlag("h") ? parseInt(checkFlag("h")) : false;
  3824.     var angled = checkFlag("a") ? true : false;
  3825.    
  3826.     var mat = (gMat == airMat) ? new SingleBlockPattern(block) : gMat;
  3827.  
  3828.     var dirInfo = getDirection();  
  3829.  
  3830.     if (!angled)    {
  3831.         if ((dirInfo.rightAngle == 0) || (dirInfo.rightAngle == 180))   {
  3832.             var tmpSize = xSize;
  3833.             xSize = zSize;
  3834.             zSize = tmpSize;
  3835.         }
  3836.     }
  3837.    
  3838.     var step = angled ? .7 : 1;
  3839.     for (var x = 0; x < xSize; x += step) {
  3840.         for (var y = 0; y < ySize; y += step) {
  3841.             for (var z = 0; z < zSize; z += step) {
  3842.                
  3843.                  if (hollow)    {
  3844.                     if (((x >= hollow) && (x < xSize-hollow)) && ((y >= hollow) && (y < ySize-hollow)) && ((z >= hollow) && (z < zSize-hollow)))    {
  3845.                         if(!insideBlock) {continue;}
  3846.                        
  3847.                         var pt = vec.add((x-xSize/2), (y*invert+invert), (z-zSize/2));
  3848.                         if (angled) {pt = rotateVec(vec, pt, dirInfo.yaw);}
  3849.                        
  3850.                         session.setBlock(pt, insideBlock);
  3851.                         continue;
  3852.                        
  3853.                     }
  3854.                  }
  3855.        
  3856.                 var pt = vec.add((x-xSize/2), (y*invert+invert), (z-zSize/2));
  3857.                 if (angled) {pt = rotateVec(vec, pt, dirInfo.yaw);}
  3858.        
  3859.                 session.setBlock(pt, mat);
  3860.             }
  3861.         }
  3862.     }
  3863. }
  3864.  
  3865. function BuildEllipse(vec, session) {
  3866.  
  3867.     var xSize = checkFlag("x") ? parseInt(checkFlag("x")) : 16;
  3868.     var ySize = checkFlag("y") ? parseInt(checkFlag("y")) : 8;
  3869.     var zSize = checkFlag("z") ? parseInt(checkFlag("z")) : 48;
  3870.     var block = checkFlag("b") ? parseBlock(checkFlag("b")) :  new BaseBlock(20);
  3871.     var insideBlock = checkFlag("i") ? parseBlock(checkFlag("i")) :  false;
  3872.     var hollow = checkFlag("h") ? true : false;
  3873.     var angled = checkFlag("a") ? true : false;
  3874.    
  3875.     var mat = (gMat == airMat) ? new SingleBlockPattern(block) : gMat;
  3876.     var dirInfo = getDirection();
  3877.  
  3878.     function lengthSq(x, y, z) {return (x * x) + (y * y) + (z * z);}
  3879.    
  3880.     var xOff = ['1', '-1', '1', '1', '-1', '1', '-1', '-1'];
  3881.     var yOff = ['1', '1', '-1', '1', '-1', '-1', '1', '-1'];
  3882.     var zOff = ['1', '1', '1', '-1', '1', '-1', '-1', '-1'];
  3883.  
  3884.     radiusX = xSize/2 + 0.5;
  3885.     radiusY = ySize/2 + 0.5;
  3886.     radiusZ = zSize/2 + 0.5;
  3887.  
  3888.     var invRadiusX = 1 / radiusX;
  3889.     var invRadiusY = 1 / radiusY;
  3890.     var invRadiusZ = 1 / radiusZ;
  3891.  
  3892.     var ceilRadiusX = Math.ceil(radiusX);
  3893.     var ceilRadiusY = Math.ceil(radiusY);
  3894.     var ceilRadiusZ = Math.ceil(radiusZ);
  3895.    
  3896.     var step = angled ? .7 : 1;
  3897.     var nextXn = 0;
  3898.     forX: for (var x = 0; x <= ceilRadiusX; x += step) {
  3899.         var xn = nextXn;
  3900.         nextXn = (x + 1) * invRadiusX;
  3901.         var nextYn = 0;
  3902.         forY: for (var y = 0; y <= ceilRadiusY; y += step) {
  3903.             var yn = nextYn;
  3904.             nextYn = (y + 1) * invRadiusY;
  3905.             var nextZn = 0;
  3906.             forZ: for (var z = 0; z <= ceilRadiusZ; z += step) {
  3907.                 var zn = nextZn;
  3908.                 nextZn = (z + 1) * invRadiusZ;
  3909.  
  3910.                 var distanceSq = lengthSq(xn, yn, zn);
  3911.                 if (distanceSq > 1) {
  3912.                     if (z == 0) {
  3913.                         if (y == 0) {
  3914.                             break forX;
  3915.                         }
  3916.                         break forY;
  3917.                     }
  3918.                     break forZ;
  3919.                 }
  3920.  
  3921.                 if (hollow) {
  3922.                     if (lengthSq(nextXn, yn, zn) <= 1 && lengthSq(xn, nextYn, zn) <= 1 && lengthSq(xn, yn, nextZn) <= 1) {
  3923.                         if (insideBlock)    {
  3924.                             for (var dirLoop = 0; dirLoop <= 7 ; dirLoop++) {
  3925.                            
  3926.                                 var setPnt = vec.add(x * xOff[dirLoop], y * yOff[dirLoop], z * zOff[dirLoop]);
  3927.                                 if (angled) {setPnt = rotateVec(vec, setPnt, dirInfo.yaw);}
  3928.                                 session.setBlock(setPnt, insideBlock);
  3929.                             }
  3930.                            
  3931.                         }
  3932.                         continue;
  3933.                     }
  3934.                 }
  3935.                
  3936.                
  3937.                 for (var dirLoop = 0; dirLoop <= 7 ; dirLoop++) {
  3938.  
  3939.                     var setPnt = vec.add(x * xOff[dirLoop], y * yOff[dirLoop], z * zOff[dirLoop]);
  3940.                     if (angled) {setPnt = rotateVec(vec, setPnt, dirInfo.yaw);}
  3941.                     session.setBlock(setPnt, mat);
  3942.                    
  3943.                 }
  3944.             }
  3945.         }
  3946.     }
  3947.  
  3948.  
  3949.  
  3950.  
  3951. }
  3952.  
  3953. function BuildSpiral(vec, session)  {
  3954.  
  3955.     var radius = checkFlag("r") ? parseInt(checkFlag("r")) : 10;
  3956.     var compress = checkFlag("s") ? parseInt(checkFlag("s")) : 8;
  3957.     var coilCnt = checkFlag("c") ? parseInt(checkFlag("c")) : 3;
  3958.     var dFlag = checkFlag("d") ? true : false;
  3959.     var hFlag = checkFlag("f") ? true : false;
  3960.  
  3961.     //var mat = (gMat == airMat) ? new SingleBlockPattern(block) : gMat;
  3962.     radius = gSize != -1 ? gSize : radius;
  3963.     compress = compress == 0 ? 1 : compress;
  3964.  
  3965.     var origin = vec;
  3966.     var cb = context.getSession().getClipboard();
  3967.     cb.copy(session);
  3968.  
  3969.     if(radius <= 0) {
  3970.        
  3971.         radius = radius * .1;
  3972.         var increment = .01;
  3973.         var maxAngle = Math.PI * 2 * coilCnt;
  3974.         var gap = Math.abs(radius);
  3975.  
  3976.         for (var angle = 0; angle <= maxAngle; angle = angle + increment)
  3977.         {
  3978.             var newX = (angle * gap * Math.cos(angle));
  3979.             var newY = (angle * gap * Math.sin(angle));
  3980.             var newZ = (angle/(compress/10))
  3981.            
  3982.             if (hFlag) {
  3983.                 var pt = origin.add(newX, newY*invert, newZ);
  3984.                 if (dFlag)  {
  3985.                     var pt2 = origin.add((-newX), (-newY*invert), newZ);
  3986.                 }
  3987.             }
  3988.             else {
  3989.                 var pt = origin.add(newX, newZ*invert, newY);
  3990.                 if (dFlag)  {
  3991.                     var pt2 = origin.add((-newX), (newZ*invert), (-newY));
  3992.                 }
  3993.             }
  3994.             cb.paste(session, pt, true);
  3995.            
  3996.             if (dFlag)  {
  3997.                 cb.paste(session, pt2, true);
  3998.             }
  3999.         }
  4000.     }
  4001.     else    {
  4002.    
  4003.         var points = 256;
  4004.         var slice = 2 * Math.PI / points;
  4005.         var pt;
  4006.         var loopCnt = 0;
  4007.         for (var i = 0; i < (points * coilCnt); i++)    {
  4008.  
  4009.             var angle = slice * i;
  4010.  
  4011.             var newX = (radius * Math.cos(angle));
  4012.             var newY = (radius * Math.sin(angle));
  4013.             var newZ = (i/(compress*2));
  4014.            
  4015.             if (hFlag) {
  4016.                 var pt = origin.add(newX, newY*invert, newZ);
  4017.                 if (dFlag)  {
  4018.                     var pt2 = origin.add(-newX, (-newY*invert), newZ);
  4019.                 }
  4020.             }
  4021.             else    {
  4022.                 var pt = origin.add(newX, newZ*invert, newY);
  4023.                 if (dFlag)  {
  4024.                     var pt2 = origin.add(-newX, newZ*invert, -newY);
  4025.                 }
  4026.             }
  4027.             cb.paste(session, pt, true);
  4028.            
  4029.             if (dFlag)  {
  4030.                 cb.paste(session, pt2, true);
  4031.             }
  4032.         }  
  4033.     }
  4034.    
  4035. }
  4036.  
  4037. function BuildMineSweeper(vec, session) {
  4038.  
  4039.     var xSize = checkFlag("x") ? parseInt(checkFlag("x")) : 24;
  4040.     var zSize = checkFlag("y") ? parseInt(checkFlag("y")) : 12;
  4041.     var mineTotal = checkFlag("m") ? parseInt(checkFlag("m")) : 40;
  4042.    
  4043.     if (checkFlag("b")) {
  4044.         xSize = 9;
  4045.         zSize = 9;
  4046.         mineTotal = 10;
  4047.     }
  4048.     if (checkFlag("i")) {
  4049.         xSize = 16;
  4050.         zSize = 16;
  4051.         mineTotal = 40;
  4052.     }
  4053.     if (checkFlag("e")) {
  4054.         xSize = 16;
  4055.         zSize = 30;
  4056.         mineTotal = 99;
  4057.     }
  4058.    
  4059. //      -x+y|0x+y|+x+y          Offset reference
  4060. //      -x0y|####|+x0y
  4061. //      -x-y|0x-y|+x-y
  4062.  
  4063.     offsetList = {          //Helpful when checking around a block
  4064.         1: Vector(-1,0,1),
  4065.         2: Vector(-1,0,0),
  4066.         3: Vector(-1,0,-1),
  4067.         4: Vector(0,0,1),
  4068.         5: Vector(0,0,-1),
  4069.         6: Vector(1,0,1),
  4070.         7: Vector(1,0,0),
  4071.         8: Vector(1,0,-1)
  4072.     };
  4073.        
  4074.     mineBlocks = {          //Block set for # of mines in the area
  4075.         0: new BaseBlock(BlockID.STONE, 0),         //No mines
  4076.         1: new BaseBlock(BlockID.COAL_ORE, 0),      //One mine 
  4077.         2: new BaseBlock(BlockID.IRON_ORE, 0),      //Two mines...
  4078.         3: new BaseBlock(BlockID.GOLD_ORE, 0),
  4079.         4: new BaseBlock(BlockID.LAPIS_LAZULI_ORE, 0), 
  4080.         5: new BaseBlock(BlockID.REDSTONE_ORE, 0),
  4081.         6: new BaseBlock(BlockID.DIAMOND_ORE, 0),
  4082.         7: new BaseBlock(BlockID.EMERALD_ORE, 0),
  4083.         8: new BaseBlock(BlockID.OBSIDIAN, 0),
  4084.         9: new BaseBlock(46, 0),                //Mine Block
  4085.         10: new BaseBlock(42, 0),               //Surface Block
  4086.         11: new BaseBlock(98, 0),               //Wall Base Block
  4087.         12: new BaseBlock(139, 0),              //Wall Block
  4088.         13: new BaseBlock(123, 0)               //Flag Marker
  4089.     };
  4090.    
  4091.     if (checkFlag("w")) {
  4092.         mineBlocks = {          //Alt Wool block set for # of mines in the area
  4093.             0: new BaseBlock(35, 0),
  4094.             1: new BaseBlock(35, 3),
  4095.             2: new BaseBlock(35, 5),
  4096.             3: new BaseBlock(35, 6),
  4097.             4: new BaseBlock(35, 11),  
  4098.             5: new BaseBlock(35, 14),
  4099.             6: new BaseBlock(35, 9),
  4100.             7: new BaseBlock(35, 13),
  4101.             8: new BaseBlock(35, 7),
  4102.             9: new BaseBlock(35, 15),
  4103.             10: new BaseBlock(42, 0),
  4104.             11: new BaseBlock(98, 0),
  4105.             12: new BaseBlock(139, 0), 
  4106.             13: new BaseBlock(19, 0)   
  4107.         };
  4108.     }
  4109.     var fieldMin = vec.add(-xSize/2, 0, -zSize/2);
  4110.     var startTime = new Date();
  4111.  
  4112.     if (checkFlag("c"))
  4113.         mineBlocks[10] = new BaseBlock(20, 0);
  4114.    
  4115.     var mines = [];
  4116.    
  4117.     var arrayWidth = xSize;
  4118.     var arrayHeight = zSize;
  4119.    
  4120.     var mines = new Array(xSize)                //array to hold mine positions
  4121.     for (var x = 0; x < xSize; x++) {
  4122.         mines[x] = new Array(zSize);
  4123.         for (var z = 0; z < zSize; z++) {
  4124.             mines[x][z] = 0;
  4125.         }
  4126.     }
  4127.    
  4128.     var legendPos = vec.add(xSize/2+4, 1, -4);
  4129.     for(var inc = 0; inc < 9; inc++)    {
  4130.         session.setBlock(legendPos.add(0,0,inc), mineBlocks[inc]);
  4131.     }
  4132.     session.setBlock(legendPos.add(0,0,-1), mineBlocks[13]);
  4133.     session.setBlock(legendPos.add(0,0,9), mineBlocks[9]);
  4134.    
  4135.     for (x = -1; x < xSize+1; x++)  {                   //Creating the base minefield
  4136.         for (z = -1; z < zSize+1; z++)  {
  4137.             var pos = vec.add(x - xSize/2, 0, z - zSize/2);
  4138.             session.setBlock(pos.add(0,-2,0), mineBlocks[11]);
  4139.             for(var y = 1; y < 11; y++) { session.setBlock(pos.add(0,y,0), new BaseBlock(0)); }     //clear some space above
  4140.            
  4141.             if((x == -1) || (x == xSize) || (z == -1) || (z == zSize))  {       //Walls and perimeter
  4142.                 session.setBlock(pos, mineBlocks[11]);                          //Underground stone brick layers
  4143.                 session.setBlock(pos.add(0,-1,0), mineBlocks[11]);
  4144.                
  4145.                 if((x == parseInt(xSize/2)) || (z == parseInt(zSize/2))) { continue; }
  4146.                
  4147.                 if ((xSize%2) == 1) {
  4148.                     if (x == xSize/2) { continue; }
  4149.                 }
  4150.                 else    {
  4151.                     if (x == xSize/2) { continue; }
  4152.                     if (x+1 == xSize/2) { continue; }
  4153.                 }
  4154.                
  4155.                 if ((zSize%2) == 1) {
  4156.                     if (z == zSize/2) { continue; }
  4157.                 }
  4158.                 else    {
  4159.                     if (z == zSize/2) { continue; }
  4160.                     if (z+1 == zSize/2) { continue; }
  4161.                 }
  4162.                
  4163.                
  4164.                
  4165.                 session.setBlock(pos.add(0,1,0), mineBlocks[12]);
  4166.             }  
  4167.             else    {                                                           //Center Area
  4168.                 session.setBlock(pos, mineBlocks[10]);
  4169.             }
  4170.            
  4171.         }
  4172.     }
  4173.    
  4174.     var missCnt = 0;
  4175.     for (m = 0; m < mineTotal; m += 0)  {           //Setting the mines
  4176.    
  4177.         var x = parseInt(Math.random()*xSize);
  4178.         var z = parseInt(Math.random()*zSize);
  4179.        
  4180.         //player.print("x@" + x + "| z@" + z);
  4181.        
  4182.         var pos = fieldMin.add(x, 0, z);
  4183.         //var pos = vec.add(parseInt(x - size/2), 0, parseInt(z - size/2));
  4184.         //player.print("pos@" + pos);
  4185.        
  4186.        
  4187.         missCnt++;
  4188.         if (mines[x][z] == 0)   {          
  4189.             session.setBlock(pos.add(0,-1,0), mineBlocks[9]);
  4190.             //player.print("mine set @" + pos + mineBlocks[9]);
  4191.             mines[x][z] = 1;
  4192.             m++;
  4193.             missCnt = 0;
  4194.         }
  4195.        
  4196.         if(missCnt > 1000)  {
  4197.             player.print("I couldn't find anymore spots to put mines!");
  4198.             player.print("I found room for a total of " + m + " mines.");
  4199.             m = mineTotal;
  4200.             missCnt = 0;
  4201.         }
  4202.     }
  4203.  
  4204.     player.print(text.Gold + "Finished creating minefield!");
  4205.     player.print(text.Gold + mineTotal + text.White + " mines set in a " + text.Gold + xSize + " x " + zSize + text.White + " area - " + text.Gold + (m/(xSize*zSize)*100).toFixed(1) + text.White + "% density.");
  4206.    
  4207.     for (x = 0; x < xSize; x++) {                   //Setting color blocks
  4208.         for (z = 0; z < zSize; z++) {
  4209.            
  4210.             pos = vec.add(x - xSize/2, -1, z - zSize/2);
  4211.            
  4212.             //if (session.getBlock(pos) == mineBlocks[10])  {
  4213.            
  4214.             if (mines[x][z] == 0)   {
  4215.            
  4216.                 var areaMines = 0;
  4217.                
  4218.                 for (px = -1; px <= 1; px++)    {                   //Looping thru neighbor blocks
  4219.                     for (pz = -1; pz <= 1; pz++)    {
  4220.                         posX = x + px;
  4221.                         posZ = z + pz;
  4222.                        
  4223.                         if((posX < 0) || (posX >= xSize) || (posZ < 0) || (posZ >= zSize)   )   {continue;}
  4224.                        
  4225.                         if (mines[posX][posZ] == 1)
  4226.                             areaMines++;
  4227.                    
  4228.                    
  4229.                     }
  4230.                 }
  4231.                
  4232.                 session.setBlock(pos, mineBlocks[areaMines]);
  4233.        
  4234.             }
  4235.        
  4236.         }
  4237.     }
  4238.  
  4239.     var sweeperTool = new DoubleActionTraceTool({           //Creating the sweeper tool
  4240.         canUse : function(player) {
  4241.             return player.hasPermission("worldedit.tool.wand");
  4242.         },
  4243.         actSecondary : function(server,config,player,session) {         // ###### Left Click - Clear Block
  4244.        
  4245.             try {
  4246.                 var vec = player.getBlockTrace(200, false);
  4247.                 if (vec == null) { return; }
  4248.                
  4249.                 var es = session.createEditSession(player);
  4250.                
  4251.                 if (es.getBlock(vec).equals(mineBlocks[10]))    {           //check if the surface block was clicked
  4252.                     var es = session.createEditSession(player);
  4253.                     var testBlock = es.getBlock(vec.add(0,-1,0));
  4254.                     es.setBlock(vec.add(0,0,0), testBlock);            
  4255.                    
  4256.                     if (testBlock.equals(mineBlocks[0]))    {           //if mine count is zero attempt to expand area
  4257.                        
  4258.                         var expandList = [];
  4259.                         var expandSide = [];
  4260.                        
  4261.                         expandList.push(vec.add(0,-1,0));
  4262.                        
  4263.                         for (var inc = 0;  inc < expandList.length; inc++)  {
  4264.                            
  4265.                             for(var side in offsetList) {       //check all the sides for more open areas, if found push them to be checked also
  4266.                                 if (es.getBlock(expandList[inc].add(offsetList[side])).equals(mineBlocks[0]) && es.getBlock(expandList[inc].add(offsetList[side].add(0,1,0))).equals(mineBlocks[10]))   {
  4267.                                     if (String(expandList).indexOf(String(expandList[inc].add(offsetList[side]))) == -1)    {
  4268.                                         expandList.push(expandList[inc].add(offsetList[side]));
  4269.                                     }                              
  4270.                                 }
  4271.                             }
  4272.                            
  4273.                             if(inc > 500000)    {           //check to see if the expanding gets too far out of control
  4274.                                 player.print("inc over 500,000!");
  4275.                                 player.print("length=" + expandList.length);
  4276.                                 session.remember(es);
  4277.                                 return;
  4278.                             }
  4279.                            
  4280.                             es.setBlock(expandList[inc].add(0,1,0), mineBlocks[0]);
  4281.                            
  4282.                             for(var side in offsetList) {       //open up all the blocks around clear area
  4283.                                 if (es.getBlock(expandList[inc].add(offsetList[side].add(0,1,0))).equals(mineBlocks[10]))
  4284.                                     expandSide.push(expandList[inc].add(offsetList[side].add(0,1,0)));
  4285.                             }
  4286.                         }
  4287.                        
  4288.                         for (var inc in expandSide) {
  4289.                             es.setBlock(expandSide[inc], es.getBlock(expandSide[inc].add(0,-1,0)));
  4290.                         }
  4291.                     }
  4292.                 }
  4293.                
  4294.                 else{                                                   //check if a numbered block was clicked
  4295.                     var tCnt = 0;
  4296.                     for (var tInc = 1; tInc < 10; tInc++)   {
  4297.                         if (es.getBlock(vec).equals(mineBlocks[tInc]))     
  4298.                             tCnt = tInc;
  4299.                    
  4300.                     }
  4301.                 }
  4302.                
  4303.                 if (tCnt > 0)   {               //if a numbered block was found
  4304.                    
  4305.                     var flagCnt = 0;
  4306.                    
  4307.                     for (var side in offsetList)    {       //open up all the blocks around clear area
  4308.                         if (es.getBlock(vec.add(offsetList[side])).equals(mineBlocks[13]))
  4309.                             flagCnt++;
  4310.                    
  4311.                     }
  4312.                    
  4313.                     if(flagCnt >= tCnt) {
  4314.                         for(var side in offsetList) {       //open up all the blocks around clear area
  4315.                            
  4316.                             if (!es.getBlock(vec.add(offsetList[side])).equals(mineBlocks[13]))     {
  4317.                                 es.setBlock(vec.add(offsetList[side]), es.getBlock(vec.add(offsetList[side].add(0,-1,0))));
  4318.                             }
  4319.                            
  4320.                             var testVec = vec.add(offsetList[side].add(0,-1,0));
  4321.                             var testBlock = es.getBlock(testVec);          
  4322.                            
  4323.                             if (testBlock.equals(mineBlocks[0]))    {           //if mine count is zero attempt to expand area
  4324.                                
  4325.                                 var expandList = [];
  4326.                                 var expandSide = [];
  4327.                                
  4328.                                 expandList.push(testVec);
  4329.                                
  4330.                                 for (var inc = 0;  inc < expandList.length; inc++)  {                                  
  4331.                                    
  4332.                                     for(var side in offsetList) {       //check all the sides for more open areas, if found push them to be checked also
  4333.                                         if (es.getBlock(expandList[inc].add(offsetList[side])).equals(mineBlocks[0]) && es.getBlock(expandList[inc].add(offsetList[side].add(0,1,0))).equals(mineBlocks[10]))   {
  4334.                                             if (String(expandList).indexOf(String(expandList[inc].add(offsetList[side]))) == -1)    {
  4335.                                                 expandList.push(expandList[inc].add(offsetList[side]));
  4336.                                             }                              
  4337.                                         }
  4338.                                     }
  4339.                                    
  4340.                                     if(inc > 500000)    {           //check to see if the expanding gets too far out of control
  4341.                                         player.print("inc over 500,000!");
  4342.                                         player.print("length=" + expandList.length);
  4343.                                         return;
  4344.                                     }
  4345.                                    
  4346.                                     for(var side in offsetList) {       //open up all the blocks around clear area
  4347.                                         if (es.getBlock(expandList[inc].add(offsetList[side].add(0,1,0))).equals(mineBlocks[10]))
  4348.                                             expandSide.push(expandList[inc].add(offsetList[side].add(0,1,0)));
  4349.                                     }
  4350.  
  4351.                                 }
  4352.                                
  4353.                                 for (var inc in expandSide) {
  4354.                                     es.setBlock(expandSide[inc], es.getBlock(expandSide[inc].add(0,-1,0)));
  4355.                                
  4356.                                 }
  4357.                             }                          
  4358.                         }
  4359.                     }
  4360.                 }
  4361.                
  4362.                 var tntList = [];
  4363.                 var leftCnt = 0;    //surface block count
  4364.                 //var fCnt = 0; //flag count
  4365.                 for (var x = 0; x < xSize; x++) {                   //Checking for TNT or game win
  4366.                     for (var z = 0; z < zSize; z++) {
  4367.                         var pos = fieldMin.add(x, 0, z);
  4368.                        
  4369.                         if (es.getBlock(pos).equals(mineBlocks[10]))    { leftCnt++; }
  4370.                         if (es.getBlock(pos).equals(mineBlocks[13]))    { leftCnt++; }
  4371.                        
  4372.                         if (es.getBlock(pos).equals(mineBlocks[9])) {                   //TNT was hit
  4373.                             for (var xT = 0; xT < xSize; xT++)  {                  
  4374.                                 for (var zT = 0; zT < zSize; zT++)  {
  4375.                                     var posT = fieldMin.add(xT, -1, zT);
  4376.                                     if (es.getBlock(posT).equals(mineBlocks[9]))    {
  4377.                                         es.setBlock(posT.add(0,1,0), mineBlocks[9]);
  4378.                                         if (checkFlag("h"))
  4379.                                             es.setBlock(posT.add(0,0,0), new BaseBlock(76));
  4380.                                     }
  4381.                                    
  4382.                                 }
  4383.                             }
  4384.                            
  4385.                             player.print("\n" + text.Red + text.Bold + "BOOOOOOM!!!!" + text.White + " You hit TNT, and are now dead. Better luck next time!");
  4386.                             session.setTool(player.getItemInHand(), null)
  4387.                             return;
  4388.                         }
  4389.                     }
  4390.                 }  
  4391.                
  4392.                 if(leftCnt == mineTotal)    {
  4393.                
  4394.                     var totalTime = (new Date() - startTime)/1000;
  4395.                     player.print("\n" + text.Gold + text.Bold + "-------- You Win!! --------");
  4396.                     player.print(text.White + "You cleared " + text.Gold + mineTotal + text.White + " mines from a " + text.Gold + xSize + " x " + zSize + text.White + " area in " + text.Gold + totalTime.toFixed(1) + text.White + " secs!");
  4397.                    
  4398.                     var diamonds = new BaseItemStack(264, 1);
  4399.                     for (var xT = 0; xT < xSize; xT++)  {                  
  4400.                         for (var zT = 0; zT < zSize; zT++)  {
  4401.                             var posT = fieldMin.add(xT, -1, zT);
  4402.                             if (es.getBlock(posT).equals(mineBlocks[9]))    {
  4403.                                 es.setBlock(posT.add(0,1,0), mineBlocks[9]);
  4404.                                 player.getWorld().dropItem(posT.add(0,30,0), diamonds, 1);
  4405.                             }
  4406.                            
  4407.                         }
  4408.                     }
  4409.                    
  4410.                     session.setTool(player.getItemInHand(), null)
  4411.                     return;
  4412.  
  4413.                 }
  4414.                
  4415.             }
  4416.             catch (e)   {
  4417.                 player.print("error=" + e);
  4418.             }
  4419.            
  4420.             return;
  4421.         },
  4422.        
  4423.         actPrimary : function(server,config,player,session) {           // ###### Right Click - Set Marker
  4424.            
  4425.             try {
  4426.                 var vec = player.getBlockTrace(200, false);
  4427.                 if (vec == null) { return; }
  4428.                 var es = session.createEditSession(player);
  4429.                
  4430.                 if (es.getBlock(vec).equals(mineBlocks[10]))    {           //Set Flag
  4431.                     es.setBlock(vec.add(0,0,0), mineBlocks[13]);
  4432.                 }
  4433.                 else if (es.getBlock(vec).equals(mineBlocks[13]))   {       //Remove Flag
  4434.                     es.setBlock(vec.add(0,0,0), mineBlocks[10]);
  4435.                 }
  4436.                 else    {
  4437.                    
  4438.                     var flagCnt = 0;
  4439.                     for (var x = 0; x < xSize; x++) {                   //Checking for flags
  4440.                         for (var z = 0; z < zSize; z++) {
  4441.                             var pos = fieldMin.add(x, 0, z);
  4442.                            
  4443.                             if (es.getBlock(pos).equals(mineBlocks[13]))    { flagCnt++; }
  4444.                            
  4445.                         }
  4446.                     }
  4447.                     var totalTime = (new Date() - startTime)/1000;
  4448.                     player.print(text.White + "Mines Left: " + text.Gold + (mineTotal-flagCnt) + text.White + "  Current Time: " + text.Gold + totalTime.toFixed(1) + text.White + " secs.");
  4449.                
  4450.                 }
  4451.                
  4452.             }
  4453.             catch (e)   {
  4454.                 player.print("error=" + e);
  4455.            
  4456.             }              
  4457.                
  4458.             return;
  4459.  
  4460.         }, 
  4461.     });
  4462.    
  4463.     context.getSession().setTool(player.getItemInHand(), sweeperTool);
  4464.    
  4465. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement