public void FloodFillAt(WorldEdit worldEdit, Block blockToPlace, ItemStack withItemStack, int posX, int posY, int posZ)
        {
            bfsQueue.Clear();
            fillablePositions.Clear();


            if (posY <= 0 || posY >= mapheight - 1)
            {
                return;
            }

            bfsQueue.Enqueue(new Vec4i(posX, posY, posZ, 0));
            fillablePositions.Add(new BlockPos(posX, posY, posZ));

            float radius = SearchRadius;

            BlockFacing[] faces  = Mode == 2 ? BlockFacing.HORIZONTALS : BlockFacing.ALLFACES;
            BlockPos      curPos = new BlockPos();

            while (bfsQueue.Count > 0)
            {
                Vec4i bpos = bfsQueue.Dequeue();

                foreach (BlockFacing facing in faces)
                {
                    curPos.Set(bpos.X + facing.Normali.X, bpos.Y + facing.Normali.Y, bpos.Z + facing.Normali.Z);

                    Block block    = blockAccessRev.GetBlock(curPos);
                    bool  inBounds = bpos.W < radius;

                    if (inBounds)
                    {
                        if (block.Replaceable >= 6000 && !fillablePositions.Contains(curPos))
                        {
                            bfsQueue.Enqueue(new Vec4i(curPos.X, curPos.Y, curPos.Z, bpos.W + 1));
                            fillablePositions.Add(curPos.Copy());
                        }
                    }
                    else
                    {
                        if (CheckEnclosure)
                        {
                            fillablePositions.Clear();
                            bfsQueue.Clear();
                            worldEdit.Bad("Cannot flood fill here, not enclosed area. Enforce enclosed area or disable enclosure check.");
                            break;
                        }
                    }
                }
            }

            foreach (BlockPos p in fillablePositions)
            {
                blockAccessRev.SetBlock(blockToPlace.BlockId, p, withItemStack);
            }

            worldEdit.Bad(fillablePositions.Count + " blocks placed");
        }
Beispiel #2
0
        public override void OnBuild(WorldEdit.WorldEdit worldEdit, int oldBlockId, BlockSelection blockSel, ItemStack withItemStack)
        {
            if (treeGenerators == null)
            {
                treeGenerators = new TreeGeneratorsUtil(worldEdit.sapi);
            }

            if (TreeVariant == null)
            {
                worldEdit.Bad("Please select a tree variant first.");
                return;
            }

            //blockAccessRev.SetBlock(oldBlockId, blockSel.Position, withItemStack);
            worldEdit.sapi.World.BlockAccessor.SetBlock(oldBlockId, blockSel.Position);
            blockSel.Position.Add(blockSel.Face.Opposite); // - prevented trees from growing o.O   - seems to work again and with this disabled trees float in the air 0.O

            blockAccessRev.ReadFromStagedByDefault = true;

            treeGenerators.ReloadTreeGenerators();
            treeGenerators.RunGenerator(new AssetLocation(TreeVariant), blockAccessRev, blockSel.Position, MinTreeSize + (float)rand.NextDouble() * (MaxTreeSize - MinTreeSize));

            blockAccessRev.SetHistoryStateBlock(blockSel.Position.X, blockSel.Position.Y, blockSel.Position.Z, oldBlockId, blockAccessRev.GetStagedBlockId(blockSel.Position));
            blockAccessRev.Commit();
        }
Beispiel #3
0
        public override void OnBuild(WorldEdit.WorldEdit worldEdit, ushort oldBlockId, BlockSelection blockSel, ItemStack withItemStack)
        {
            if (treeGenerators == null)
            {
                treeGenerators = new TreeGeneratorsUtil(worldEdit.sapi);
            }

            if (TreeVariant == null)
            {
                worldEdit.Bad("Please select a tree variant first.");
                return;
            }

            //blockAccessRev.SetBlock(oldBlockId, blockSel.Position, withItemStack);
            worldEdit.sapi.World.BlockAccessor.SetBlock(oldBlockId, blockSel.Position);
            blockSel.Position.Add(blockSel.Face.GetOpposite());

            blockAccessRev.ReadFromStagedByDefault = true;

            treeGenerators.ReloadTreeGenerators();
            treeGenerators.RunGenerator(new AssetLocation(TreeVariant), blockAccessRev, blockSel.Position.DownCopy(), MinTreeSize + (float)rand.NextDouble() * (MaxTreeSize - MinTreeSize));

            blockAccessRev.SetHistoryStateBlock(blockSel.Position.X, blockSel.Position.Y, blockSel.Position.Z, oldBlockId, blockAccessRev.GetStagedBlockId(blockSel.Position));
            blockAccessRev.Commit();
        }
Beispiel #4
0
        public void LoadBlockdatas(ICoreServerAPI api, WorldEdit worldEdit = null)
        {
            this.blockDatas = new BlockSchematic[0];

            if (BlockDataFilenames == null)
            {
                return;
            }
            string[] filenames = BlockDataFilenames.Split(',');

            List <BlockSchematic> blockDatas = new List <BlockSchematic>();
            string exportFolderPath          = api.GetOrCreateDataPath("WorldEdit");

            int failed = 0;

            for (int i = 0; i < filenames.Length; i++)
            {
                string infilepath = Path.Combine(exportFolderPath, filenames[i]);

                string         error     = "";
                BlockSchematic blockData = BlockSchematic.LoadFromFile(infilepath, ref error);
                if (blockData == null)
                {
                    worldEdit?.Bad(error);
                    failed++;
                }
                else
                {
                    blockDatas.Add(blockData);
                }
            }

            if (failed > 0)
            {
                worldEdit?.Bad(failed + " schematics couldn't be loaded.");
            }

            this.blockDatas = blockDatas.ToArray();
        }
        public override bool OnWorldEditCommand(WorldEdit worldEdit, CmdArgs args)
        {
            switch (args.PopWord())
            {
            case "magic":
            {
                MagicSelect = (bool)args.PopBool(false);

                worldEdit.Good("Magic select now " + (MagicSelect ? "on" : "off"));
                return(true);
            }

            case "edgeblocks":
            {
                string arg = args.PopWord("list");

                switch (arg)
                {
                case "list":
                    worldEdit.Good("Edge blocks: " + string.Join(", ", EdgeBlocks));
                    break;

                case "add":
                    string blockcode = args.PopAll();

                    if (matchesAnyBlock(worldEdit.sapi, blockcode))
                    {
                        EdgeBlocks = EdgeBlocks.Append(args.PopAll());
                        worldEdit.Good("Ok, edge block '" + blockcode + "' added.");
                        SetEdgeBlocks(worldEdit.sapi.World, EdgeBlocks);
                    }
                    else
                    {
                        worldEdit.Good("Error, block code/wildcard '" + blockcode + "' does not match any known blocks.");
                    }


                    break;

                case "remove":

                    List <string> elems = new List <string>(EdgeBlocks);
                    if (elems.Remove(args.PopAll()))
                    {
                        worldEdit.Good("Ok, edge block removed.");
                        SetEdgeBlocks(worldEdit.sapi.World, elems.ToArray());
                    }
                    else
                    {
                        worldEdit.Good("No such edge block in list.");
                    }

                    break;

                default:
                    worldEdit.Bad("Invalid arg. Syntax: /we edgeblocks or /we edgeblocks [list|add|remove] [blockcode]");
                    break;
                }
            }
                return(true);
            }

            return(false);
        }
Beispiel #6
0
        public override bool OnWorldEditCommand(WorldEdit worldEdit, CmdArgs args)
        {
            switch (args[0])
            {
            case "imc":
                if (workspace.clipboardBlockData != null)
                {
                    this.blockDatas = new BlockSchematic[] { workspace.clipboardBlockData };
                    worldEdit.Good("Ok, using copied blockdata");
                    nextRnd = 0;
                    workspace.ResendBlockHighlights(worldEdit);
                }
                else
                {
                    worldEdit.Good("No copied block data available");
                }
                return(true);

            case "ims":
                string        exportFolderPath = worldEdit.sapi.GetOrCreateDataPath("WorldEdit");
                List <string> filenames        = new List <string>();

                for (int i = 1; i < args.Length; i++)
                {
                    string filename = Path.GetFileName(args[i]);
                    string filepath = Path.Combine(exportFolderPath, args[i]);

                    if (!filename.EndsWith("*") && !filename.EndsWith("/") && !filename.EndsWith(".json"))
                    {
                        filename += ".json";
                    }

                    try
                    {
                        string[] foundFilePaths = Directory.GetFiles(Path.GetDirectoryName(filepath), filename);

                        for (int j = 0; j < foundFilePaths.Length; j++)
                        {
                            filenames.Add(foundFilePaths[j].Substring(exportFolderPath.Length + 1));
                        }
                    } catch (Exception)
                    {
                        worldEdit.Bad("Unable to read files from this source");
                        return(true);
                    }
                }



                if (filenames.Count > 0)
                {
                    BlockDataFilenames = string.Join(",", filenames);
                    LoadBlockdatas(worldEdit.sapi, worldEdit);
                    worldEdit.Good("Ok, found " + filenames.Count + " block data source files");
                }
                else
                {
                    BlockDataFilenames = null;
                    this.blockDatas    = new BlockSchematic[0];

                    worldEdit.Good("No source files under this name/wildcard found");
                }

                nextRnd = rand.Next(blockDatas.Length);

                workspace.ResendBlockHighlights(worldEdit);

                return(true);

            case "imo":
                Origin = EnumOrigin.BottomCenter;

                if (args.Length > 1)
                {
                    int origin;
                    int.TryParse(args[1], out origin);
                    if (Enum.IsDefined(typeof(EnumOrigin), origin))
                    {
                        Origin = (EnumOrigin)origin;
                    }
                }

                worldEdit.Good("Paste origin " + Origin + " set.");

                workspace.ResendBlockHighlights(worldEdit);

                return(true);

            case "tm":
                ReplaceMode = EnumReplaceMode.Replaceable;

                if (args.Length > 1)
                {
                    int replaceable = 0;
                    int.TryParse(args[1], out replaceable);
                    if (Enum.IsDefined(typeof(EnumReplaceMode), replaceable))
                    {
                        ReplaceMode = (EnumReplaceMode)replaceable;
                    }
                }

                worldEdit.Good("Replace mode " + ReplaceMode + " set.");
                workspace.ResendBlockHighlights(worldEdit);

                return(true);

            case "imrrand":
                RandomRotate = args.Length > 1 && (args[1] == "1" || args[1] == "true" || args[1] == "on");

                worldEdit.Good("Random rotation now " + (RandomRotate ? "on" : "off"));

                SetRandomAngle(worldEdit.sapi.World);

                workspace.ResendBlockHighlights(worldEdit);

                return(true);

            case "imn":
                nextRnd = rand.Next(blockDatas.Length);
                workspace.ResendBlockHighlights(worldEdit);
                break;


            case "imr":
                if (blockDatas == null || blockDatas.Length == 0)
                {
                    worldEdit.Bad("Please define a block data source first.");
                    return(true);
                }

                int angle = 90;

                if (args.Length > 1)
                {
                    if (!int.TryParse(args[1], out angle))
                    {
                        worldEdit.Bad("Invalid Angle (not a number)");
                        return(true);
                    }
                }
                if (angle < 0)
                {
                    angle += 360;
                }

                if (angle != 0 && angle != 90 && angle != 180 && angle != 270)
                {
                    worldEdit.Bad("Invalid Angle, allowed values are -270, -180, -90, 0, 90, 180 and 270");
                    return(true);
                }

                for (int i = 0; i < blockDatas.Length; i++)
                {
                    blockDatas[i].TransformWhilePacked(worldEdit.sapi.World, EnumOrigin.BottomCenter, angle, null);
                }

                workspace.ResendBlockHighlights(worldEdit);

                worldEdit.Good("Ok, all schematics rotated by " + angle + " degrees");

                return(true);


            case "imflip":
                if (blockDatas == null || blockDatas.Length == 0)
                {
                    worldEdit.Bad("Please define a block data source first.");
                    return(true);
                }

                for (int i = 0; i < blockDatas.Length; i++)
                {
                    blockDatas[i].TransformWhilePacked(worldEdit.sapi.World, EnumOrigin.BottomCenter, 0, EnumAxis.Y);
                }

                workspace.ResendBlockHighlights(worldEdit);

                worldEdit.Good("Ok, imported sources flipped");


                return(true);


            case "immirror":
                if (blockDatas == null || blockDatas.Length == 0)
                {
                    worldEdit.Bad("Please define a block data source first.");
                    return(true);
                }

                EnumAxis axis = EnumAxis.X;
                if (args.PopWord().ToLowerInvariant() == "z")
                {
                    axis = EnumAxis.Z;
                }

                for (int i = 0; i < blockDatas.Length; i++)
                {
                    blockDatas[i].TransformWhilePacked(worldEdit.sapi.World, EnumOrigin.BottomCenter, 0, axis);
                }

                workspace.ResendBlockHighlights(worldEdit);

                worldEdit.Good("Ok, imported sources mirrored around " + axis + " axis");


                return(true);
            }

            return(false);
        }
Beispiel #7
0
        public override bool OnWorldEditCommand(WorldEdit.WorldEdit worldEdit, CmdArgs args)
        {
            if (treeGenerators == null)
            {
                treeGenerators = new TreeGeneratorsUtil(worldEdit.sapi);
            }

            string cmd = args.PopWord();

            switch (cmd)
            {
            case "tsizemin":
            {
                float size = 0.7f;
                if (args.Length > 0)
                {
                    float.TryParse(args[0], NumberStyles.Any, GlobalConstants.DefaultCultureInfo, out size);
                }
                MinTreeSize = size;

                worldEdit.Good("Tree Min Size=" + size + " set.");

                return(true);
            }

            case "tsizemax":
            {
                float size = 0.7f;
                if (args.Length > 0)
                {
                    float.TryParse(args[0], NumberStyles.Any, GlobalConstants.DefaultCultureInfo, out size);
                }
                MaxTreeSize = size;

                worldEdit.Good("Tree Max Size=" + size + " set.");

                return(true);
            }

            case "tsize":
            {
                float min = 0.7f;
                if (args.Length > 0)
                {
                    float.TryParse(args[0], NumberStyles.Any, GlobalConstants.DefaultCultureInfo, out min);
                }
                MinTreeSize = min;

                float max = 1.3f;
                if (args.Length > 1)
                {
                    float.TryParse(args[1], NumberStyles.Any, GlobalConstants.DefaultCultureInfo, out max);
                }
                MaxTreeSize = max;

                worldEdit.Good("Tree Min Size=" + min + ", max size =" + MaxTreeSize + " set.");

                return(true);
            }

            case "trnd":
                return(true);

            case "tv":
                int index = 0;

                string variant = args.PopWord();

                bool numeric = int.TryParse(variant, NumberStyles.Any, GlobalConstants.DefaultCultureInfo, out index);

                treeGenerators.ReloadTreeGenerators();

                if (numeric)
                {
                    var val = treeGenerators.GetGenerator(index);
                    if (val.Key == null)
                    {
                        worldEdit.Bad("No such tree variant found.");
                        return(true);
                    }

                    TreeVariant = val.Key.ToShortString();
                    worldEdit.Good("Tree variant " + val.Key + " set.");
                }
                else
                {
                    if (variant != null && treeGenerators.GetGenerator(new AssetLocation(variant)) != null)
                    {
                        TreeVariant = variant;
                        worldEdit.Good("Tree variant " + variant + " set.");
                    }
                    else
                    {
                        worldEdit.Bad("No such tree variant found.");
                    }
                }

                return(true);
            }

            return(false);
        }