コード例 #1
0
ファイル: StackCommand.cs プロジェクト: TheKye/Eco-WorldEdit
        protected override void Execute(WorldRange selection)
        {
            selection = selection.FixXZ(Shared.Voxel.World.VoxelSize);

            List <WorldEditBlock> blocks = new List <WorldEditBlock>();

            void DoAction(Vector3i pos)
            {
                if (WorldEditBlockManager.IsImpenetrable(pos))
                {
                    return;
                }
                WorldEditBlock sourceBlock = WorldEditBlock.Create(Eco.World.World.GetBlock(pos), pos);

                blocks.Add(sourceBlock);
            }

            selection.ForEachInc(DoAction);

            Vector3i directionOffset = this.direction.ToVec();

            switch (this.direction)
            {
            case Direction.Up:
            case Direction.Down:
                directionOffset *= selection.HeightInc + this.offset;
                break;

            case Direction.Left:
            case Direction.Right:
                directionOffset *= selection.WidthInc + this.offset;
                break;

            case Direction.Forward:
            case Direction.Back:
                directionOffset *= selection.LengthInc + this.offset;
                break;
            }

            for (int i = 1; i <= amount; i++)
            {
                Vector3i offset = directionOffset * i;

                foreach (WorldEditBlock sourceBlock in blocks)
                {
                    Vector3i finalPos = WorldEditBlockManager.ApplyOffset(sourceBlock.Position, offset);
                    if (finalPos.Y < 0 || finalPos.Y > Shared.Voxel.World.VoxelSize.Y)
                    {
                        continue;
                    }
                    this.AddBlockChangedEntry(finalPos);
                    WorldEditBlockManager.RestoreBlockOffset(sourceBlock, offset, this.UserSession);
                    this.BlocksChanged++;
                }
            }
        }
コード例 #2
0
ファイル: WallsCommand.cs プロジェクト: TheKye/Eco-WorldEdit
        protected override void Execute(WorldRange selection)
        {
            selection = selection.FixXZ(Shared.Voxel.World.VoxelSize);

            foreach (Vector3i pos in selection.SidesIterator())
            {
                if (WorldEditBlockManager.IsImpenetrable(pos))
                {
                    continue;
                }
                this.AddBlockChangedEntry(pos);
                WorldEditBlockManager.SetBlock(blockType, pos);
                this.BlocksChanged++;
            }
        }
コード例 #3
0
        protected override void Execute(WorldRange selection)
        {
            selection = selection.FixXZ(Shared.Voxel.World.VoxelSize);

            Vector3i playerPos = this.UserSession.Player.Position.Round;

            this.UserSession.Clipboard.Clear();
            void DoAction(Vector3i pos)
            {
                this.UserSession.Clipboard.Add(WorldEditBlock.Create(Eco.World.World.GetBlock(pos), pos, playerPos));
            }

            selection.ForEachInc(DoAction);
            this.UserSession.AuthorInfo.MarkDirty();
        }
コード例 #4
0
        protected override void Execute(WorldRange selection)
        {
            selection = selection.FixXZ(Shared.Voxel.World.VoxelSize);
            void DoAction(Vector3i pos)
            {
                if (WorldEditBlockManager.IsImpenetrable(pos))
                {
                    return;
                }
                this.AddBlockChangedEntry(pos);
                WorldEditBlockManager.SetBlock(blockType, pos);
                this.BlocksChanged++;
            }

            selection.ForEachInc(DoAction);
        }
コード例 #5
0
ファイル: GrowCommand.cs プロジェクト: TheKye/Eco-WorldEdit
        protected override void Execute(WorldRange selection)
        {
            selection = selection.FixXZ(Shared.Voxel.World.VoxelSize);

            void DoAction(Vector3i pos)
            {
                Block block = Eco.World.World.GetBlock(pos);

                if (block.GetType() == typeof(PlantBlock) || block.GetType() == typeof(TreeBlock))
                {
                    var pb = PlantBlock.GetPlant(pos);
                    pb.GrowthPercent = 1;
                    pb.Tended        = true;
                    pb.Tick();
                }
            }

            selection.ForEachInc(DoAction);
        }
コード例 #6
0
        protected override void Execute(WorldRange selection)
        {
            selection = selection.FixXZ(Shared.Voxel.World.VoxelSize);

            Vector3i offset = this.direction.ToVec() * this.amount;
            Stack <WorldEditBlock> blocks = new Stack <WorldEditBlock>();

            void DoAction(Vector3i pos)
            {
                if (WorldEditBlockManager.IsImpenetrable(pos))
                {
                    return;
                }
                WorldEditBlock sourceBlock = WorldEditBlock.Create(Eco.World.World.GetBlock(pos), pos);

                blocks.Push(sourceBlock);
                this.AddBlockChangedEntry(pos);
                WorldEditBlockManager.SetBlock(typeof(EmptyBlock), pos);
            }

            selection.ForEachInc(DoAction);

            while (blocks.TryPop(out WorldEditBlock sourceBlock))
            {
                Vector3i finalPos = WorldEditBlockManager.ApplyOffset(sourceBlock.Position, offset);
                if (finalPos.Y < 0 || finalPos.Y > Shared.Voxel.World.VoxelSize.Y)
                {
                    continue;
                }
                this.AddBlockChangedEntry(finalPos);
                WorldEditBlockManager.RestoreBlockOffset(sourceBlock, offset, this.UserSession);
                this.BlocksChanged++;
            }


            //Action<int, int, int> action = (int x, int y, int z) =>
            //{
            //	Vector3i pos = new Vector3i(x, y, z);
            //	if (WorldEditBlockManager.IsImpenetrable(pos)) return;
            //	AddBlockChangedEntry(pos);
            //	AddBlockChangedEntry(pos + offset);

            //	WorldEditBlock sourceBlock = WorldEditBlock.Create(Eco.World.World.GetBlock(pos), pos);
            //	WorldEditBlockManager.RestoreBlockOffset(sourceBlock, offset, this.UserSession);
            //	WorldEditBlockManager.SetBlock(typeof(EmptyBlock), pos);
            //	this.BlocksChanged++;
            //};


            //if (this.direction == Direction.Left || this.direction == Direction.Back || this.direction == Direction.Down)
            //{
            //	for (int x = vectors.Lower.X; x != vectors.Higher.X; x = (x + 1) % Shared.Voxel.World.VoxelSize.X)
            //	{
            //		for (int y = vectors.Lower.Y; y < vectors.Higher.Y; y++)
            //		{
            //			for (int z = vectors.Lower.Z; z != vectors.Higher.Z; z = (z + 1) % Shared.Voxel.World.VoxelSize.Z)
            //			{
            //				action.Invoke(x, y, z);
            //			}
            //		}
            //	}
            //}
            //else
            //{
            //	/*                for (int x = vectors.Higher.X - 1; x >= vectors.Lower.X; x--)
            //						for (int y = vectors.Higher.Y - 1; y >= vectors.Lower.Y; y--)
            //							for (int z = vectors.Higher.Z - 1; z >= vectors.Lower.Z; z--)*/

            //	int x = vectors.Higher.X - 1;
            //	if (x < 0)
            //	{
            //		x = x + Shared.Voxel.World.VoxelSize.X;
            //	}

            //	int startZ = vectors.Higher.Z - 1;
            //	if (startZ < 0)
            //	{
            //		startZ = startZ + Shared.Voxel.World.VoxelSize.Z;
            //	}

            //	//           Console.WriteLine("--------------");
            //	//           Console.WriteLine(vectors.Lower);
            //	//            Console.WriteLine(vectors.Higher);

            //	for (; x != (vectors.Lower.X - 1); x--)
            //	{
            //		if (x < 0)
            //		{
            //			x = x + Shared.Voxel.World.VoxelSize.X;
            //		}

            //		for (int y = vectors.Higher.Y - 1; y >= vectors.Lower.Y; y--)
            //		{
            //			for (int z = startZ; z != (vectors.Lower.Z - 1); z--)
            //			{
            //				if (z < 0)
            //				{
            //					z = z + Shared.Voxel.World.VoxelSize.Z;
            //				}

            //				//               Console.WriteLine($"{x} {y} {z}");
            //				action.Invoke(x, y, z);
            //			}
            //		}
            //	}
            //}
        }
コード例 #7
0
 protected override void Execute(WorldRange selection)
 {
     selection = selection.FixXZ(Shared.Voxel.World.VoxelSize);
     selection.ForEachInc(ReplaceBlock);
 }
コード例 #8
0
        protected override void Execute(WorldRange selection)
        {
            selection = selection.FixXZ(Shared.Voxel.World.VoxelSize);

            Dictionary <object, long> blocks = new Dictionary <object, long>();
            long emptyBlocks = 0;

            foreach (Vector3i pos in selection.XYZIterInc())
            {
                Block block     = Eco.World.World.GetBlock(pos);
                Type  blockType = null;
                switch (block)
                {
                case PlantBlock _:
                case TreeBlock _:
                    Plant plant = EcoSim.PlantSim.GetPlant(pos);
                    if (plant != null && plant.Position.Equals(pos))
                    {
                        blockType = plant.Species.GetType();
                    }
                    break;

                case WorldObjectBlock worldObjectBlock:
                    WorldObject worldObject = worldObjectBlock.WorldObjectHandle.Object;
                    if (worldObject.Position3i.Equals(pos))
                    {
                        blockType = worldObject.GetType();
                    }
                    break;

                default:
                    if (BlockContainerManager.Obj.IsBlockContained(pos))
                    {
                        WorldObject obj = ServiceHolder <IWorldObjectManager> .Obj.All.Where(x => x.Position3i.Equals(pos)).FirstOrDefault();

                        if (obj != null)
                        {
                            blockType = obj.GetType();
                        }
                    }
                    else
                    {
                        blockType = block.GetType();
                    }
                    break;
                }
                if (blockType != null)
                {
                    if (blockType == typeof(EmptyBlock))
                    {
                        emptyBlocks++; continue;
                    }
                    if (this.outputType.Equals("brief"))
                    {
                        string name = this.GetBlockFancyName(blockType);
                        blocks.TryGetValue(name, out long count);
                        blocks[name] = count + 1;
                    }
                    else
                    {
                        blocks.TryGetValue(blockType, out long count);
                        blocks[blockType] = count + 1;
                    }
                }
            }

            decimal totalBlocks = blocks.Values.Sum();             // (vectors.Higher.X - vectors.Lower.X) * (vectors.Higher.Y - vectors.Lower.Y) * (vectors.Higher.Z - vectors.Lower.Z);

            StringBuilder sb = new StringBuilder();

            sb.AppendLine(TextLoc.Header(Localizer.DoStr("Selection Info")));
            sb.AppendLineLoc($"Region: {Text.Location(this.UserSession.Selection.min)} - {Text.Location(this.UserSession.Selection.max)}");
            sb.Append(Localizer.DoStr("Width:").ToString().PadRight(8)).AppendLine(Text.PluralLocStr("block", "blocks", selection.WidthInc));
            sb.Append(Localizer.DoStr("Height:").ToString().PadRight(8)).AppendLine(Text.PluralLocStr("block", "blocks", selection.HeightInc));
            sb.Append(Localizer.DoStr("Length:").ToString().PadRight(8)).AppendLine(Text.PluralLocStr("block", "blocks", selection.LengthInc));
            sb.Append(Localizer.DoStr("Volume:").ToString().PadRight(8)).AppendLine(Text.PluralLocStr("block", "blocks", selection.VolumeInc));
            sb.Append(Localizer.DoStr("Area:").ToString().PadRight(8)).AppendLine(Text.PluralLocStr("block", "blocks", selection.WidthInc * selection.LengthInc));
            sb.AppendLocStr("Empty blocks:"); sb.AppendLine($" {emptyBlocks,8}");
            sb.AppendLocStr("Total blocks:"); sb.AppendLine($" {totalBlocks,8}");

            sb.AppendLine().AppendLine(TextLoc.Header(Localizer.DoStr("Block List")));
            foreach (KeyValuePair <object, long> entry in blocks)
            {
                decimal percent = Math.Round((entry.Value / totalBlocks) * 100, 2);

                sb.Append(this.outputType.Equals("detail") ? this.GetBlockFancyName((Type)entry.Key) : (string)entry.Key);
                sb.Append(Text.Pos(400, Text.Info(Text.Int(entry.Value))));
                sb.Append($"({percent}%)".PadLeft(10));
                if (this.outputType.Equals("detail"))
                {
                    sb.Append(Text.Pos(500, $"[{Localizer.DoStr(((Type)entry.Key).Name)}]"));
                }
                sb.AppendLine();
            }
            if (!string.IsNullOrEmpty(this.fileName))
            {
                this.OutputToFile(sb.ToString());
                this.UserSession.Player.MsgLoc($"Report saved into file with name <{WorldEditManager.SanitizeFileName(this.fileName)}.txt>");
            }
            this.UserSession.Player.OpenInfoPanel(Localizer.Do($"WorldEdit Blocks Report"), sb.ToString(), "WorldEditDistr");
        }