private static void OnBuildBlockRequest(MySyncGrid sync, ref BuildBlockMsg msg, MyNetworkClient sender) { MyCubeGrid.MyBlockLocation? builtBlock = null; MyEntity builder = null; MyEntities.TryGetEntityById(msg.BuilderEntityId, out builder); var buildHandler = sync.BlockBuilt; if (buildHandler != null) buildHandler(ColorExtensions.UnpackHSVFromUint(msg.ColorMaskHsv), msg.Location, msg.BlockObjectBuilder, ref builtBlock, builder); if (Sync.IsServer) { Sync.Layer.SendMessageToAll(ref msg); } var afterHandler = sync.AfterBlockBuilt; if (afterHandler != null && builtBlock != null) afterHandler(builtBlock.Value); }
//interface IBlockMessage : IEntityMessage //{ // Vector3I GetBlockPosition(); //} //delegate void BlockMessageCallback<TBlock, TMsg>(TBlock block, ref TMsg message, MyPlayer sender) // where TBlock : MyCubeBlock // where TMsg : struct, IBlockMessage; //class MyCallback<TBlock, TMsg> : MySyncLayer.MyCallbackBase<TMsg> // where TBlock : MyCubeBlock // where TMsg : struct, IBlockMessage //{ // public readonly BlockMessageCallback<TBlock, TMsg> Callback; // public MyCallback(MySyncLayer layer, BlockMessageCallback<TBlock, TMsg> callback, MyMessagePermissions permission, ISerializer<TMsg> serializer) // : base(layer, permission, serializer) // { // Callback = callback; // } // protected override void OnHandle(ref TMsg msg, MyPlayer player) // { // MySyncGrid sync = Layer.GetSyncEntity<MySyncGrid, TMsg>(msg.GetEntityId()); // if (sync != null) // { // var block = sync.Entity.GetBlock(msg.GetBlockPosition()); // if (block != null) // { // var fatBlock = block.FatBlock as TBlock; // if (fatBlock != null) // { // Callback(fatBlock, ref msg, player); // } // } // } // } //} public void BuildBlock(Vector3 colorMaskHsv, MyCubeGrid.MyBlockLocation location, MyObjectBuilder_CubeBlock blockObjectBuilder, long builderEntityId) { var msg = new BuildBlockMsg(); msg.GridEntityId = Entity.EntityId; msg.Location = location; msg.ColorMaskHsv = colorMaskHsv.PackHSVToUint(); msg.BlockObjectBuilder = blockObjectBuilder; msg.BuilderEntityId = builderEntityId; Sync.Layer.SendMessageToServer(ref msg); }