/// <summary> /// Accounts for block being added to a grid that already exist in the world /// </summary> /// <param name="grid"></param> /// <param name="block"></param> private void MyCubeGridsOnBlockBuilt(MyCubeGrid grid, MySlimBlock block) { if (grid == null || !BlockLimiterConfig.Instance.EnableLimits) { return; } //This adds grid to cache and also prevents double count from MyEntitiesOnEntityAdd if (!GridCache.TryGetGridById(grid.EntityId, out _)) { GridCache.AddGrid(grid); return; } if (_justAdded.Contains(block)) { _justAdded.Remove(block); return; } _justAdded.Add(block); GridCache.AddBlock(block); Block.IncreaseCount(block.BlockDefinition, new List <long> { block.BuiltBy }, 1, grid.EntityId); }
private void MyCubeGridsOnBlockBuilt(MyCubeGrid grid, MySlimBlock block) { if (!GridCache.TryGetGridById(grid.EntityId, out _)) { GridCache.AddGrid(grid.EntityId); return; } Block.IncreaseCount(block.BlockDefinition, block.BuiltBy, 1, grid.EntityId); }
private void MyCubeGridsOnBlockBuilt(MyCubeGrid grid, MySlimBlock block) { if (grid == null || !BlockLimiterConfig.Instance.EnableLimits) { return; } if (!GridCache.TryGetGridById(grid.EntityId, out _)) { GridCache.AddGrid(grid); return; } Block.IncreaseCount(block.BlockDefinition, block.BuiltBy, 1, grid.EntityId); }
/// <summary> /// Adds newly added grids to cache and update count to meet change /// </summary> /// <param name="entity"></param> private void MyEntitiesOnOnEntityAdd(MyEntity entity) { if (!BlockLimiterConfig.Instance.EnableLimits) { return; } if (!(entity is MyCubeGrid grid)) { return; } if (grid.Projector != null || grid.IsPreview) { return; } // Do Not Add to grid cache at this point to allow MyCubeGridsOnBlockBuild to add and prevent double counts var blocks = grid.CubeBlocks; GridCache.AddGrid(grid); foreach (var block in blocks) { if (_justAdded.Contains(block)) { _justAdded.Remove(block); continue; } _justAdded.Add(block); Block.IncreaseCount(block.BlockDefinition, block.BuiltBy == block.OwnerId ? new List <long> { block.BuiltBy } : new List <long> { block.BuiltBy, block.OwnerId }, 1, grid.EntityId); } }