public override void Init(MyObjectBuilder_CubeBlock objectBuilder, MyCubeGrid cubeGrid)
        {
            m_conveyorSorterDefinition = (MyConveyorSorterDefinition)MyDefinitionManager.Static.GetCubeBlockDefinition(objectBuilder.GetId());

            var sinkComp = new MyResourceSinkComponent();

            sinkComp.Init(
                m_conveyorSorterDefinition.ResourceSinkGroup,
                BlockDefinition.PowerInput,
                UpdatePowerInput);
            sinkComp.IsPoweredChanged += IsPoweredChanged;
            ResourceSink = sinkComp;

            base.Init(objectBuilder, cubeGrid);

            MyObjectBuilder_ConveyorSorter ob = (MyObjectBuilder_ConveyorSorter)objectBuilder;

            DrainAll    = ob.DrainAll;
            IsWhitelist = ob.IsWhiteList;

            foreach (var id in ob.DefinitionIds)
            {
                m_inventoryConstraint.Add(id);
            }
            foreach (byte b in ob.DefinitionTypes)
            {
                Tuple <MyObjectBuilderType, StringBuilder> tuple;
                if (!CandidateTypes.TryGetValue(b, out tuple))
                {
                    Debug.Assert(false, "type not in dictionary");
                    continue;
                }
                m_inventoryConstraint.AddObjectBuilderType(tuple.Item1);
            }

            if (MyFakes.ENABLE_INVENTORY_FIX)
            {
                FixSingleInventory();
            }


            if (this.GetInventory() == null)
            {
                MyInventory inventory = new MyInventory(m_conveyorSorterDefinition.InventorySize.Volume, m_conveyorSorterDefinition.InventorySize, MyInventoryFlags.CanSend);
                Components.Add <MyInventoryBase>(inventory);
                inventory.Init(ob.Inventory);
            }
            Debug.Assert(this.GetInventory().Owner == this, "Ownership was not set!");

            SlimBlock.ComponentStack.IsFunctionalChanged += ComponentStack_IsFunctionalChanged;

            NeedsUpdate |= MyEntityUpdateEnum.EACH_100TH_FRAME | MyEntityUpdateEnum.EACH_10TH_FRAME;


            ResourceSink.Update();
            UpdateText();
        }
Exemplo n.º 2
0
        public override void Init(MyObjectBuilder_CubeBlock objectBuilder, MyCubeGrid cubeGrid)
        {
            base.Init(objectBuilder, cubeGrid);

            MyObjectBuilder_ConveyorSorter ob = (MyObjectBuilder_ConveyorSorter)objectBuilder;

            DrainAll    = ob.DrainAll;
            IsWhitelist = ob.IsWhiteList;
            foreach (var id in ob.DefinitionIds)
            {
                m_inventoryConstraint.Add(id);
            }
            foreach (byte b in ob.DefinitionTypes)
            {
                Tuple <MyObjectBuilderType, StringBuilder> tuple;
                if (!CandidateTypes.TryGetValue(b, out tuple))
                {
                    Debug.Assert(false, "type not in dictionary");
                    continue;
                }
                m_inventoryConstraint.AddObjectBuilderType(tuple.Item1);
            }

            m_conveyorSorterDefinition = (MyConveyorSorterDefinition)MyDefinitionManager.Static.GetCubeBlockDefinition(objectBuilder.GetId());
            m_inventory = new MyInventory(m_conveyorSorterDefinition.InventorySize.Volume, m_conveyorSorterDefinition.InventorySize, MyInventoryFlags.CanSend, this);
            m_inventory.Init(ob.Inventory);

            SlimBlock.ComponentStack.IsFunctionalChanged += ComponentStack_IsFunctionalChanged;

            NeedsUpdate |= MyEntityUpdateEnum.EACH_100TH_FRAME | MyEntityUpdateEnum.EACH_10TH_FRAME;

            if (MyPerGameSettings.InventoryMass)
            {
                m_inventory.ContentsChanged += Inventory_ContentsChanged;
            }

            var sinkComp = new MyResourceSinkComponent();

            sinkComp.Init(
                m_conveyorSorterDefinition.ResourceSinkGroup,
                BlockDefinition.PowerInput,
                UpdatePowerInput);
            sinkComp.IsPoweredChanged += IsPoweredChanged;
            ResourceSink = sinkComp;
            ResourceSink.Update();
            UpdateText();
        }
Exemplo n.º 3
0
 public override MyObjectBuilder_CubeBlock GetObjectBuilderCubeBlock(bool copy = false)
 {
     MyObjectBuilder_ConveyorSorter objectBuilder = (MyObjectBuilder_ConveyorSorter)base.GetObjectBuilderCubeBlock(copy);
     objectBuilder.DrainAll = DrainAll;
     objectBuilder.IsWhiteList = IsWhitelist;
     objectBuilder.Inventory = this.GetInventory().GetObjectBuilder();
     foreach (var id in m_inventoryConstraint.ConstrainedIds)
         objectBuilder.DefinitionIds.Add(id);
     foreach (var type in m_inventoryConstraint.ConstrainedTypes)
     {
         byte b;
         if (!CandidateTypesToId.TryGetValue(type, out b))
         {
             Debug.Assert(false, "type not in reverse dictionary");
             continue;
         }
         objectBuilder.DefinitionTypes.Add(b);
     }
     return objectBuilder;
 }
Exemplo n.º 4
0
        public override MyObjectBuilder_CubeBlock GetObjectBuilderCubeBlock(bool copy = false)
        {
            MyObjectBuilder_ConveyorSorter objectBuilderCubeBlock = (MyObjectBuilder_ConveyorSorter)base.GetObjectBuilderCubeBlock(copy);

            objectBuilderCubeBlock.DrainAll    = this.DrainAll;
            objectBuilderCubeBlock.IsWhiteList = this.IsWhitelist;
            objectBuilderCubeBlock.Inventory   = this.GetInventory(0).GetObjectBuilder();
            foreach (MyDefinitionId id in this.m_inventoryConstraint.ConstrainedIds)
            {
                objectBuilderCubeBlock.DefinitionIds.Add((SerializableDefinitionId)id);
            }
            foreach (MyObjectBuilderType type in this.m_inventoryConstraint.ConstrainedTypes)
            {
                byte num;
                if (CandidateTypesToId.TryGetValue(type, out num))
                {
                    objectBuilderCubeBlock.DefinitionTypes.Add(num);
                }
            }
            return(objectBuilderCubeBlock);
        }
Exemplo n.º 5
0
        public override void Init(MyObjectBuilder_CubeBlock objectBuilder, MyCubeGrid cubeGrid)
        {
            this.m_conveyorSorterDefinition = (MyConveyorSorterDefinition)MyDefinitionManager.Static.GetCubeBlockDefinition(objectBuilder.GetId());
            MyResourceSinkComponent component = new MyResourceSinkComponent(1);

            component.Init(this.m_conveyorSorterDefinition.ResourceSinkGroup, this.BlockDefinition.PowerInput, new Func <float>(this.UpdatePowerInput));
            component.IsPoweredChanged += new Action(this.IsPoweredChanged);
            base.ResourceSink           = component;
            base.Init(objectBuilder, cubeGrid);
            MyObjectBuilder_ConveyorSorter sorter = (MyObjectBuilder_ConveyorSorter)objectBuilder;

            this.m_drainAll.SetLocalValue(sorter.DrainAll);
            this.IsWhitelist = sorter.IsWhiteList;
            foreach (SerializableDefinitionId id in sorter.DefinitionIds)
            {
                this.m_inventoryConstraint.Add(id);
            }
            foreach (byte num in sorter.DefinitionTypes)
            {
                Tuple <MyObjectBuilderType, StringBuilder> tuple;
                if (CandidateTypes.TryGetValue(num, out tuple))
                {
                    this.m_inventoryConstraint.AddObjectBuilderType(tuple.Item1);
                }
            }
            if (MyFakes.ENABLE_INVENTORY_FIX)
            {
                base.FixSingleInventory();
            }
            if (this.GetInventory(0) == null)
            {
                MyInventory inventory = new MyInventory(this.m_conveyorSorterDefinition.InventorySize.Volume, this.m_conveyorSorterDefinition.InventorySize, MyInventoryFlags.CanSend);
                base.Components.Add <MyInventoryBase>(inventory);
                inventory.Init(sorter.Inventory);
            }
            base.SlimBlock.ComponentStack.IsFunctionalChanged += new Action(this.ComponentStack_IsFunctionalChanged);
            base.NeedsUpdate |= MyEntityUpdateEnum.EACH_100TH_FRAME | MyEntityUpdateEnum.EACH_10TH_FRAME;
            base.ResourceSink.Update();
            this.UpdateText();
        }