private static void OnBuildBlocksRequest(MySyncGrid sync, ref BuildBlocksMsg msg, MyNetworkClient sender) { if (msg.Locations == null) { Debug.Fail("Invalid message"); return; } m_tmpBuildList.Clear(); Debug.Assert(m_tmpBuildList != msg.Locations, "The build block message was received via loopback using the temporary build list. This causes erasing ot the message."); MyEntity builder = null; MyEntities.TryGetEntityById(msg.BuilderEntityId, out builder); MyCubeBuilder.BuildComponent.GetBlocksPlacementMaterials(msg.Locations, sync.Entity); if (!MyCubeBuilder.BuildComponent.HasBuildingMaterials(builder)) return; { var handler = sync.BlocksBuilt; if (handler != null) handler(ColorExtensions.UnpackHSVFromUint(msg.ColorMaskHsv), msg.Locations, m_tmpBuildList, builder); } if (Sync.IsServer && m_tmpBuildList.Count > 0) { // Broadcast to clients, use result collection msg.Locations = m_tmpBuildList; Sync.Layer.SendMessageToAll(ref msg); } { var handler = sync.AfterBlocksBuilt; if (handler != null) handler(m_tmpBuildList); } }
public void BuildBlocks(Vector3 colorMaskHsv, HashSet<MyCubeGrid.MyBlockLocation> locations, long builderEntityId) { var msg = new BuildBlocksMsg(); msg.GridEntityId = Entity.EntityId; msg.Locations = locations; msg.ColorMaskHsv = colorMaskHsv.PackHSVToUint(); msg.BuilderEntityId = builderEntityId; Sync.Layer.SendMessageToServer(ref msg); }