Advertisement
midspace

MyProjectorBlockerLogic

Aug 24th, 2015
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.57 KB | None | 0 0
  1. namespace midspace
  2. {
  3.     using Sandbox.Common;
  4.     using Sandbox.Common.Components;
  5.     using Sandbox.Common.ObjectBuilders;
  6.     using Sandbox.Common.ObjectBuilders.VRageData;
  7.     using Sandbox.Game.Entities.Blocks;
  8.     using Sandbox.ModAPI;
  9.     using System;
  10.     using VRage;
  11.     using VRage.Components;
  12.     using VRage.ModAPI;
  13.     using VRage.ObjectBuilders;
  14.     using VRageMath;
  15.  
  16.     /// <summary>
  17.     /// This will test preventing the setting of a Projection.
  18.     /// For :{CC} Lethegrin
  19.     /// </summary>
  20.     [MyEntityComponentDescriptor(typeof(MyObjectBuilder_Projector))]
  21.     public class MyProjectorBlockerLogic : MyGameLogicComponent
  22.     {
  23.         private MyObjectBuilder_EntityBase _objectBuilder;
  24.  
  25.         private MyObjectBuilder_CubeGrid _gridObjectBuilder;
  26.  
  27.         public override void Close()
  28.         {
  29.         }
  30.  
  31.         public override void Init(MyObjectBuilder_EntityBase objectBuilder)
  32.         {
  33.             _objectBuilder = objectBuilder;
  34.             Entity.NeedsUpdate |= MyEntityUpdateEnum.EACH_100TH_FRAME;
  35.  
  36.             // dummy grid for testing.
  37.             _gridObjectBuilder = new MyObjectBuilder_CubeGrid()
  38.             {
  39.                 PersistentFlags = MyPersistentEntityFlags2.CastShadows | MyPersistentEntityFlags2.InScene,
  40.                 GridSizeEnum = MyCubeSize.Large,
  41.                 IsStatic = false,
  42.                 LinearVelocity = new SerializableVector3(0, 0, 0),
  43.                 AngularVelocity = new SerializableVector3(0, 0, 0),
  44.                 PositionAndOrientation = new MyPositionAndOrientation(),
  45.                 DisplayName = "Empty."
  46.             };
  47.  
  48.             MyObjectBuilder_Warhead cube = new MyObjectBuilder_Warhead()
  49.             {
  50.                 Min = new SerializableVector3I(0, 0, 0),
  51.                 SubtypeName = "LargeWarhead",
  52.                 ColorMaskHSV = new SerializableVector3(0, -1, 0),
  53.                 EntityId = 0,
  54.                 Owner = 0,
  55.                 BlockOrientation = new SerializableBlockOrientation(Base6Directions.Direction.Forward, Base6Directions.Direction.Up),
  56.                 ShareMode = MyOwnershipShareModeEnum.All,
  57.                 CustomName = "Hello. My name is Inigo Montoya. You killed my father. Prepare to die.",
  58.             };
  59.  
  60.             _gridObjectBuilder.CubeBlocks.Add(cube);
  61.         }
  62.  
  63.         public override void MarkForClose()
  64.         {
  65.         }
  66.  
  67.         public override void UpdateAfterSimulation()
  68.         {
  69.         }
  70.  
  71.         public override void UpdateAfterSimulation10()
  72.         {
  73.         }
  74.  
  75.         public override void UpdateAfterSimulation100()
  76.         {
  77.             try
  78.             {
  79.                 var projector = Entity as Sandbox.ModAPI.Ingame.IMyProjector;
  80.                 //projector.LoadBlueprint(...)'   // Blueprint's are client specific, and using this in a Multi Player game is NOT going to work.
  81.  
  82.                 MyProjector p = (MyProjector)projector;
  83.  
  84.                 // Option 1.
  85.                 // This may work...
  86.                 var cube = Entity as MyObjectBuilder_Projector;
  87.  
  88.                 if (cube == null)
  89.                 {
  90.                     MyAPIGateway.Utilities.ShowNotification("cube is null.", 500, MyFontEnum.White);
  91.                     return;
  92.                 }
  93.  
  94.                 if (cube.ProjectedGrid == null || cube.ProjectedGrid.BlockGroups.Count == 0 || cube.ProjectedGrid.BlockGroups[0].Blocks.Count == 0)
  95.                 {
  96.                     MyAPIGateway.Utilities.ShowNotification("Projection blanked.", 3000, MyFontEnum.Blue);
  97.                     p.Init(_gridObjectBuilder);  // Set a new grid here, and see if it works.
  98.                 }
  99.  
  100.                 //// Option 2.
  101.                 //if (cube.ProjectedGrid != null)
  102.                 //{
  103.                 //    MyAPIGateway.Utilities.ShowNotification("Projection blanked.", 3000, MyFontEnum.Blue);
  104.                 //    cube.ProjectedGrid = _gridObjectBuilder;
  105.                 //}
  106.             }
  107.             catch(Exception ex)
  108.             {
  109.                 MyAPIGateway.Utilities.ShowMessage("Exception", ex.ToString());
  110.             }
  111.         }
  112.  
  113.         public override void UpdateBeforeSimulation()
  114.         {
  115.         }
  116.  
  117.         public override void UpdateBeforeSimulation10()
  118.         {
  119.         }
  120.  
  121.         public override void UpdateBeforeSimulation100()
  122.         {
  123.         }
  124.  
  125.         public override void UpdateOnceBeforeFrame()
  126.         {
  127.         }
  128.  
  129.         public override MyObjectBuilder_EntityBase GetObjectBuilder(bool copy = false)
  130.         {
  131.             return copy ? Entity.GetObjectBuilder() : _objectBuilder;
  132.         }
  133.     }
  134. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement