コード例 #1
0
        private void ReplaceBlock(Vector3i pos)
        {
            if (WorldEditBlockManager.IsImpenetrable(pos))
            {
                return;
            }
            Block block = Eco.World.World.GetBlock(pos);

            if (block == null)
            {
                return;
            }
            if (this.blockTypeToReplace != null)
            {
                if (block.GetType() == this.blockTypeToFind)
                {
                    this.AddBlockChangedEntry(pos);
                    WorldEditBlockManager.SetBlock(this.blockTypeToReplace, pos);
                    this.BlocksChanged++;
                }
            }
            else
            {
                if (block.GetType() != typeof(EmptyBlock))
                {
                    this.AddBlockChangedEntry(pos);
                    WorldEditBlockManager.SetBlock(this.blockTypeToFind, pos);
                    this.BlocksChanged++;
                }
            }
        }
コード例 #2
0
        protected override void Execute(WorldRange selection)
        {
            Vector3 pos    = this.UserSession.Player.Position;
            var     newpos = new Vector3i((int)pos.X, (int)pos.Y + this.count, (int)pos.Z);

            WorldEditBlockManager.SetBlock(typeof(StoneBlock), newpos);
            newpos.Y += 2;
            this.UserSession.Player.SetPosition(newpos);
        }
コード例 #3
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++;
                }
            }
        }
コード例 #4
0
 private void Restore(List <WorldEditBlock> list)
 {
     foreach (WorldEditBlock entry in list)
     {
         Vector3i pos = WorldEditBlockManager.ApplyOffset(entry.Position, this.playerPos);
         if (WorldEditBlockManager.IsImpenetrable(pos))
         {
             continue;
         }
         AddBlockChangedEntry(pos);
         WorldEditBlockManager.RestoreBlockOffset(entry, this.playerPos, this.UserSession);
     }
 }
コード例 #5
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++;
            }
        }
コード例 #6
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);
        }
コード例 #7
0
        public bool Undo()
        {
            bool result = false;

            try
            {
                this.PerformingUndo = true;
                this.timer.Restart();
                if (this.affectedBlocks != null)
                {
                    this.AffectedBlocks.Where(b => !b.IsPlantBlock() || !b.IsWorldObjectBlock()).ForEach(b =>
                    {
                        WorldEditBlockManager.RestoreBlock(b, b.Position, this.UserSession);
                    });
                    this.AffectedBlocks.Where(b => b.IsPlantBlock() || b.IsWorldObjectBlock()).ForEach(b =>
                    {
                        WorldEditBlockManager.RestoreBlock(b, b.Position, this.UserSession);
                    });
                    result = true;
                }
                this.timer.Stop();
            }
            catch (WorldEditCommandException e)
            {
                this.UserSession.Player.ErrorLocStr(e.Message);
            }
            finally
            {
                if (this.timer.IsRunning)
                {
                    this.timer.Stop();
                }
                this.PerformingUndo = false;
            }
            return(result);
        }
コード例 #8
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);
            //			}
            //		}
            //	}
            //}
        }