示例#1
0
        private void Add(IMySlimBlock obj, bool fromAddInitialized = false)
        {
            MySlimBlock         block  = (MySlimBlock)obj;
            MyObjectBuilderType typeId = block.BlockDefinition.Id.TypeId;
            List <MySlimBlock>  blockList;

            if (!CubeBlocks.TryGetValue(typeId, out blockList))
            {
                blockList = new List <MySlimBlock>();
                CubeBlocks.Add(typeId, blockList);
            }
            Log.DebugLog("already in blockList: " + obj.nameWithId(), Logger.severity.ERROR, condition: blockList.Contains(block));
            blockList.Add(block);

            IMyTerminalBlock term = block.FatBlock as IMyTerminalBlock;

            if (term != null)
            {
                if (DefinitionType.TrySet(((MyCubeBlock)term).BlockDefinition.Id, term.DefinitionDisplayNameText))
                {
                    Log.DebugLog("new type: " + term.DefinitionDisplayNameText, Logger.severity.DEBUG);
                }
                TerminalBlocks++;
            }

            Vector3I cellSize = block.Max - block.Min + 1;

            CellCount += cellSize.X * cellSize.Y * cellSize.Z;
        }
示例#2
0
        private void CubeGrid_OnBlockRemoved(IMySlimBlock obj)
        {
            lock_blocks.AcquireExclusive();
            try
            {
                MySlimBlock         block  = (MySlimBlock)obj;
                MyObjectBuilderType typeId = block.BlockDefinition.Id.TypeId;
                List <MySlimBlock>  blockList;
                if (!CubeBlocks.TryGetValue(typeId, out blockList))
                {
                    Log.DebugLog("failed to get list of type: " + typeId, Logger.severity.WARNING);
                    return;
                }
                if (!blockList.Remove(block))
                {
                    Log.DebugLog("already removed: " + obj.nameWithId(), Logger.severity.WARNING);
                    return;
                }

                Log.DebugLog("block removed: " + obj.nameWithId(), Logger.severity.TRACE);
                //Logger.DebugNotify("block removed: " + obj.getBestName(), level: Logger.severity.TRACE);

                if (blockList.Count == 0)
                {
                    CubeBlocks.Remove(typeId);
                }
                if (block.FatBlock is IMyTerminalBlock)
                {
                    TerminalBlocks--;
                }

                Vector3I cellSize = block.Max - block.Min + 1;
                CellCount -= cellSize.X * cellSize.Y * cellSize.Z;
            }
            catch (Exception e) { Log.AlwaysLog("Exception: " + e, Logger.severity.ERROR); }
            finally { lock_blocks.ReleaseExclusive(); }
        }