public bool IsConnectionFine(MySlimBlock blockA, MySlimBlock blockB)
 {
     return(true);
 }
 public void Remove(MySlimBlock block)
 {
     m_selectedGrid = block.CubeGrid;
 }
 public void Add(MySlimBlock block)
 {
     m_selectedGrid = block.CubeGrid;
 }
Esempio n. 4
0
 public ProjectionRaycastData(MyProjector.BuildCheckResult result, MySlimBlock cubeBlock, MyProjector projector)
 {
     raycastResult = result;
     hitCube       = cubeBlock;
     cubeProjector = projector;
 }
        public static bool FindRandomCollectableItemInPlaceArea(long entityId, HashSet <MyDefinitionId> itemDefinitions, out BlockInfo result)
        {
            result = default(BlockInfo);

            MyPlaceArea area = MyPlaceArea.FromEntity(entityId);

            if (area == null)
            {
                return(false);
            }

            var             areaBoundingBox = area.WorldAABB;
            List <MyEntity> entities        = null;

            try
            {
                entities = MyEntities.GetEntitiesInAABB(ref areaBoundingBox);

                MySlimBlock first = null;
                for (int i = entities.Count - 1; i >= 0; i--)
                {
                    var entity = entities[i];

                    if (MyManipulationTool.IsEntityManipulated(entity))
                    {
                        entities.RemoveAtFast(i);
                        continue;
                    }

                    var cubeGrid = entity as MyCubeGrid;
                    if (cubeGrid == null || cubeGrid.BlocksCount != 1)
                    {
                        entities.RemoveAtFast(i);
                        continue;
                    }

                    first = cubeGrid.CubeBlocks.First();
                    if (!itemDefinitions.Contains(first.BlockDefinition.Id))
                    {
                        entities.RemoveAtFast(i);
                        continue;
                    }
                }

                if (entities.Count() == 0)
                {
                    return(false);
                }

                int cubeIndex    = (int)Math.Round(MyRandom.Instance.NextFloat() * (entities.Count() - 1));
                var selectedCube = entities[cubeIndex] as MyCubeGrid;
                first = selectedCube.GetBlocks().First();

                result.GridEntityId          = selectedCube.EntityId;
                result.BlockPosition         = first.Position;
                result.ComponentDefinitionId = GetComponentId(first);

                return(true);
            }
            finally
            {
                entities.Clear();
            }
        }
        public static bool FindClosestCollectableItemInPlaceArea(Vector3D fromPosition, long entityId, HashSet <MyDefinitionId> itemDefinitions, out BlockInfo result)
        {
            List <MyEntity> entities = null;

            result = default(BlockInfo);
            try
            {
                MyEntity    containingEntity = null;
                MyPlaceArea area             = null;

                if (!MyEntities.TryGetEntityById(entityId, out containingEntity))
                {
                    return(false);
                }
                if (!containingEntity.Components.TryGet <MyPlaceArea>(out area))
                {
                    return(false);
                }

                var areaBoundingBox = area.WorldAABB;
                entities = MyEntities.GetEntitiesInAABB(ref areaBoundingBox);

                MyCubeGrid  closestGrid           = null;
                MySlimBlock first                 = null;
                double      closestCubeDistanceSq = double.MaxValue;

                foreach (var entity in entities)
                {
                    if (MyManipulationTool.IsEntityManipulated(entity))
                    {
                        continue;
                    }

                    if (entity is MyCubeGrid)
                    {
                        var cubeGrid = entity as MyCubeGrid;
                        if (cubeGrid.BlocksCount == 1)
                        {
                            first = cubeGrid.CubeBlocks.First();
                            if (itemDefinitions.Contains(first.BlockDefinition.Id))
                            {
                                var worldPosition = cubeGrid.GridIntegerToWorld(first.Position);
                                var cubeDistanceFromCharacterSq = Vector3D.DistanceSquared(worldPosition, fromPosition);

                                if (cubeDistanceFromCharacterSq < closestCubeDistanceSq)
                                {
                                    closestCubeDistanceSq = cubeDistanceFromCharacterSq;
                                    closestGrid           = cubeGrid;
                                }
                            }
                        }
                    }
                }

                if (closestGrid == null)
                {
                    return(false);
                }

                first = closestGrid.CubeBlocks.First();

                result.GridEntityId          = closestGrid.EntityId;
                result.BlockPosition         = first.Position;
                result.ComponentDefinitionId = GetComponentId(first);

                return(true);
            }
            finally
            {
                if (entities != null)
                {
                    entities.Clear();
                }
            }
        }