public void Update()
        {
            Point16 check = Utility.TileEntityTopLeft(position);

            if (TileEntity.ByPosition.ContainsKey(check))
            {
                TileEntity te = TileEntity.ByPosition[check];

                if (IO == IO.In && te is IEnergyProvider)
                {
                    IEnergyProvider provider = (IEnergyProvider)te;
                    long            delta    = grid.energy.ReceiveEnergy(Utility.Min(grid.energy.GetMaxReceive(), provider.GetEnergyStorage().GetMaxExtract(), provider.GetEnergy()));
                    provider.GetEnergyStorage().ModifyEnergyStored(-delta);
                    Net.SendGridEnergy(position, delta);
                }
                else if (IO == IO.Out && te is IEnergyReceiver)
                {
                    IEnergyReceiver receiver = (IEnergyReceiver)te;
                    long            delta    = -grid.energy.ExtractEnergy(Utility.Min(grid.energy.GetMaxExtract(), receiver.GetEnergyStorage().GetMaxReceive(), receiver.GetCapacity() - receiver.GetEnergy()));
                    receiver.GetEnergyStorage().ModifyEnergyStored(-delta);
                    Net.SendGridEnergy(position, delta);
                }
            }
        }
Beispiel #2
0
 public static float GetProgress(IEnergyReceiver storage) => storage.GetEnergyStorage().GetEnergy() / (float)storage.GetEnergyStorage().GetCapacity();