Ejemplo n.º 1
0
        public MySlimBlock PlaceInGrid(
            MyDefinitionId blockDefinitionId,
            MyCubeGrid currentGrid,
            Vector3I min,
            Vector3I orientationForward,
            Vector3I orientationUp,
            long playerId
            )
        {
            HashSet <MyCubeGrid.MyBlockLocation> blocksBuildQueue = new HashSet <MyCubeGrid.MyBlockLocation>();
            var orientation     = Quaternion.CreateFromForwardUp(orientationForward, orientationUp);
            var myBlockLocation = new MyCubeGrid.MyBlockLocation(
                blockDefinitionId, min, min, min, orientation, MyEntityIdentifier.AllocateId(),
                playerId
                );

            blocksBuildQueue.Add(myBlockLocation);
            var blockIds = currentGrid.CubeBlocks.Select(b => b.UniqueId).ToImmutableHashSet();

            currentGrid.BuildBlocks(MyPlayer.SelectedColor, MyStringHash.GetOrCompute(MyPlayer.SelectedArmorSkin),
                                    blocksBuildQueue, MySession.Static.LocalCharacterEntityId, MySession.Static.LocalPlayerId);
            var blockIds2 = currentGrid.CubeBlocks.Select(b => b.UniqueId).ToImmutableHashSet();
            var newIds    = blockIds2.Except(blockIds);

            if (newIds.IsEmpty)
            {
                throw new InvalidOperationException("Couldn't build the block");
            }

            if (newIds.Count > 1)
            {
                throw new InvalidOperationException("Built more than one block!");
            }

            var id = newIds.First();

            return(currentGrid.CubeBlocks.First(b => b.UniqueId == id));
        }