Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace midspace
- {
- using Sandbox.Common;
- using Sandbox.Common.Components;
- using Sandbox.Common.ObjectBuilders;
- using Sandbox.Common.ObjectBuilders.VRageData;
- using Sandbox.Game.Entities.Blocks;
- using Sandbox.ModAPI;
- using System;
- using VRage;
- using VRage.Components;
- using VRage.ModAPI;
- using VRage.ObjectBuilders;
- using VRageMath;
- /// <summary>
- /// This will test preventing the setting of a Projection.
- /// For :{CC} Lethegrin
- /// </summary>
- [MyEntityComponentDescriptor(typeof(MyObjectBuilder_Projector))]
- public class MyProjectorBlockerLogic : MyGameLogicComponent
- {
- private MyObjectBuilder_EntityBase _objectBuilder;
- private MyObjectBuilder_CubeGrid _gridObjectBuilder;
- public override void Close()
- {
- }
- public override void Init(MyObjectBuilder_EntityBase objectBuilder)
- {
- _objectBuilder = objectBuilder;
- Entity.NeedsUpdate |= MyEntityUpdateEnum.EACH_100TH_FRAME;
- // dummy grid for testing.
- _gridObjectBuilder = new MyObjectBuilder_CubeGrid()
- {
- PersistentFlags = MyPersistentEntityFlags2.CastShadows | MyPersistentEntityFlags2.InScene,
- GridSizeEnum = MyCubeSize.Large,
- IsStatic = false,
- LinearVelocity = new SerializableVector3(0, 0, 0),
- AngularVelocity = new SerializableVector3(0, 0, 0),
- PositionAndOrientation = new MyPositionAndOrientation(),
- DisplayName = "Empty."
- };
- MyObjectBuilder_Warhead cube = new MyObjectBuilder_Warhead()
- {
- Min = new SerializableVector3I(0, 0, 0),
- SubtypeName = "LargeWarhead",
- ColorMaskHSV = new SerializableVector3(0, -1, 0),
- EntityId = 0,
- Owner = 0,
- BlockOrientation = new SerializableBlockOrientation(Base6Directions.Direction.Forward, Base6Directions.Direction.Up),
- ShareMode = MyOwnershipShareModeEnum.All,
- CustomName = "Hello. My name is Inigo Montoya. You killed my father. Prepare to die.",
- };
- _gridObjectBuilder.CubeBlocks.Add(cube);
- }
- public override void MarkForClose()
- {
- }
- public override void UpdateAfterSimulation()
- {
- }
- public override void UpdateAfterSimulation10()
- {
- }
- public override void UpdateAfterSimulation100()
- {
- try
- {
- var projector = Entity as Sandbox.ModAPI.Ingame.IMyProjector;
- //projector.LoadBlueprint(...)' // Blueprint's are client specific, and using this in a Multi Player game is NOT going to work.
- MyProjector p = (MyProjector)projector;
- // Option 1.
- // This may work...
- var cube = Entity as MyObjectBuilder_Projector;
- if (cube == null)
- {
- MyAPIGateway.Utilities.ShowNotification("cube is null.", 500, MyFontEnum.White);
- return;
- }
- if (cube.ProjectedGrid == null || cube.ProjectedGrid.BlockGroups.Count == 0 || cube.ProjectedGrid.BlockGroups[0].Blocks.Count == 0)
- {
- MyAPIGateway.Utilities.ShowNotification("Projection blanked.", 3000, MyFontEnum.Blue);
- p.Init(_gridObjectBuilder); // Set a new grid here, and see if it works.
- }
- //// Option 2.
- //if (cube.ProjectedGrid != null)
- //{
- // MyAPIGateway.Utilities.ShowNotification("Projection blanked.", 3000, MyFontEnum.Blue);
- // cube.ProjectedGrid = _gridObjectBuilder;
- //}
- }
- catch(Exception ex)
- {
- MyAPIGateway.Utilities.ShowMessage("Exception", ex.ToString());
- }
- }
- public override void UpdateBeforeSimulation()
- {
- }
- public override void UpdateBeforeSimulation10()
- {
- }
- public override void UpdateBeforeSimulation100()
- {
- }
- public override void UpdateOnceBeforeFrame()
- {
- }
- public override MyObjectBuilder_EntityBase GetObjectBuilder(bool copy = false)
- {
- return copy ? Entity.GetObjectBuilder() : _objectBuilder;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement