Ejemplo n.º 1
0
        public void AddBlockChangedEntry(Vector3i position)
        {
            Block          block          = World.GetBlock(position);
            WorldEditBlock worldEditBlock = WorldEditBlock.Create(block, position);

            this.AffectedBlocks.Push(worldEditBlock);
        }
Ejemplo n.º 2
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++;
                }
            }
        }
Ejemplo n.º 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();
        }
Ejemplo n.º 4
0
        protected override void Execute(WorldRange selection)
        {
            AffineTransform transform = new AffineTransform();
            float           radians   = Mathf.DegToRad(this.angleDegrees);

            transform = transform.RotateY(radians);

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

            blocks.AddRange(this.UserSession.Clipboard.GetBlocks());
            blocks.AddRange(this.UserSession.Clipboard.GetPlants());
            blocks.AddRange(this.UserSession.Clipboard.GetWorldObjects());

            for (int i = 0; i < blocks.Count; i++)
            {
                WorldEditBlock block = blocks[i];
                block.RotateBlock(transform, this.angleDegrees, radians);
                blocks[i] = block;
            }

            this.UserSession.Clipboard.Clear();
            this.UserSession.Clipboard.Parse(blocks);
        }
Ejemplo n.º 5
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);
            //			}
            //		}
            //	}
            //}
        }