コード例 #1
0
 public override void Tick()
 {
     tick++;
     if (tick >= 10)
     {
         Vector3i startPosition = Position3i + Vector3i.Up * 3;
         foreach (RubbleObject obj in NetObjectManager.GetObjectsOfType <RubbleObject>())
         {
             if (Vector3.Distance(obj.Position, Position + Vector3.Up * 1) < 1.5f)
             {
                 if (obj.IsBreakable)
                 {
                     obj.Breakup();
                 }
                 else if (entry.GetLinker() != null)
                 {
                     ConnectorObject output = entry.GetLinker().GetFirstValidOutput(this, obj.GetType());
                     if (output != null)
                     {
                         obj.TryPickup(output.Output.GetComponent <PublicStorageComponent>().Inventory);
                     }
                 }
             }
         }
         tick = 0;
     }
 }
コード例 #2
0
 private void BlockChanged(Vector3i pos)
 {
     if (entry.GetLinker() != null)
     {
         Vector3i startPosition = Position3i + Vector3i.Up * 3;
         for (int i = -1; i <= 1; i++)
         {
             for (int j = -1; j <= 1; j++)
             {
                 if (pos == startPosition + new Vector3i(i, 0, j))
                 {
                     Type blockType = World.GetBlock(pos).GetType();
                     if (blockType == typeof(EmptyBlock))
                     {
                         continue;
                     }
                     BlockItem       item = BlockItem.CreatingItem(blockType);
                     ConnectorObject obj  = entry.GetLinker().GetFirstValidOutput(this, item.GetType());
                     if (obj == null)
                     {
                         continue;
                     }
                     obj.Output.GetComponent <PublicStorageComponent>().Inventory.TryAddItem(item);
                     World.DeleteBlock(pos);
                 }
             }
         }
     }
 }
コード例 #3
0
ファイル: QuarryObject.cs プロジェクト: Kirthos/KirthosMods
        public override void Tick()
        {
            actualMiningTime += WorldObjectManager.TickDeltaTime;
            if (actualMiningTime >= MINING_TIME && Operating)
            {
                Vector3i previousMiningBlock = blockMinedPos;
                blockMinedPos += Rotation.Right.Floor;
                int testPos = 0;
                if (Rotation.Right.Floor.x < 0)
                {
                    testPos = -blockMinedPos.x;
                }
                else if (Rotation.Right.Floor.x > 0)
                {
                    testPos = blockMinedPos.x;
                }
                else if (Rotation.Right.Floor.z < 0)
                {
                    testPos = -blockMinedPos.z;
                }
                else if (Rotation.Right.Floor.z > 0)
                {
                    testPos = blockMinedPos.z;
                }
                if (testPos == (MINING_SIZE / 2) + 1)
                {
                    blockMinedPos += Rotation.Forward.Floor;
                    blockMinedPos += -Rotation.Right.Floor * MINING_SIZE;
                }

                if (Rotation.Forward.Floor.x < 0)
                {
                    testPos = -blockMinedPos.x;
                }
                else if (Rotation.Forward.Floor.x > 0)
                {
                    testPos = blockMinedPos.x;
                }
                else if (Rotation.Forward.Floor.z < 0)
                {
                    testPos = -blockMinedPos.z;
                }
                else if (Rotation.Forward.Floor.z > 0)
                {
                    testPos = blockMinedPos.z;
                }

                if (testPos == MINING_SIZE + 1)
                {
                    blockMinedPos += -Rotation.Up.Floor;
                    blockMinedPos += -Rotation.Forward.Floor * MINING_SIZE;
                }
                Block minedBlock = World.GetBlock(blockMinedPos + Position3i);
                if (minedBlock.Is <Impenetrable>())
                {
                    GetComponent <OnOffComponent>().SetOnOff(Creator.Player, false);
                    blockMinedPos = previousMiningBlock;
                    return;
                }
                Item minedItem = null;
                if (minedBlock.Is <Diggable>())
                {
                    minedItem = BlockItem.CreatingItem(minedBlock.GetType());
                }
                if (minedBlock.Is <Minable>())
                {
                    if (minedBlock is StoneBlock)
                    {
                        minedItem = Item.Create(typeof(StoneItem));
                    }
                    else if (minedBlock is CoalBlock)
                    {
                        minedItem = Item.Create(typeof(CoalItem));
                    }
                    else if (minedBlock is CopperOreBlock)
                    {
                        minedItem = Item.Create(typeof(CopperOreItem));
                    }
                    else if (minedBlock is IronOreBlock)
                    {
                        minedItem = Item.Create(typeof(IronOreItem));
                    }
                    else if (minedBlock is GoldOreBlock)
                    {
                        minedItem = Item.Create(typeof(GoldOreItem));
                    }
                }
                if (minedItem != null && entry.GetLinker() != null)
                {
                    //, minedBlock.Is<Minable>() ? 4 : 1
                    ConnectorObject obj = entry.GetLinker().GetFirstValidOutput(this, minedItem.GetType());
                    if (obj == null)
                    {
                        blockMinedPos = previousMiningBlock;
                        return;
                    }
                    obj.Output.GetComponent <PublicStorageComponent>().Inventory.TryAddItems(minedItem.Type, minedBlock.Is <Minable>() ? 4 : 1);
                }
                World.DeleteBlock(blockMinedPos + Position3i);
                actualMiningTime = 0;
            }
        }