Beispiel #1
0
        public override void Init(MyObjectBuilder_EntityBase objectBuilder)
        {
            // this method is called async! always do stuff in the first update unless you're sure it must be in this one.
            // NOTE the objectBuilder arg is not the Entity's but the component's, and since the component wasn't loaded from an OB that means it's always null, which it is (AFAIK).

            block = (IMyPowerProducer)Entity;

            if (MyAPIGateway.Multiplayer.IsServer)
            {
                NeedsUpdate = MyEntityUpdateEnum.BEFORE_NEXT_FRAME | MyEntityUpdateEnum.EACH_100TH_FRAME | MyEntityUpdateEnum.EACH_FRAME; // allow UpdateOnceBeforeFrame() to execute, remove if not needed
            }
            var inv = (MyInventory)block.GetInventory();

            //if(inv == null)
            //{
            //    inv = new MyInventory();
            //    block.Components.Add(inv);
            //}

            MyLog.Default.WriteLine($"got inventory {block.HasInventory} {inv} {inv == null}");
            MyLog.Default.WriteLine($"got Constraint {inv.Constraint} {inv.Constraint == null}");

            inv.Constraint.Add(new MyDefinitionId(typeof(MyObjectBuilder_Ore), "Ice"));
            MyLog.Default.WriteLine("add constraint");
        }
Beispiel #2
0
        public override void UpdateAfterSimulation100()
        {
            if (block.CubeGrid?.Physics == null) // ignore projected and other non-physical grids
            {
                return;
            }


            var MWs = Interlocked.Exchange(ref powerAccumealtor, 0);
            var MWh = MWs / (60 * 60);

            var iceMade = MWh / MWH_PER_KG_OF_ICE;

            //MyAPIGateway.Utilities.ShowMessage("hgen", $"p={MWh}MWh, i={iceMade}kg");

            block.GetInventory().AddItems((VRage.MyFixedPoint)iceMade, Ice);
        }