Esempio n. 1
0
        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++;
                }
            }
        }
Esempio n. 2
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);
     }
 }
Esempio n. 3
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);
            //			}
            //		}
            //	}
            //}
        }