src/main/java/dev/rlnt/energymeter/meter/MeterTile.java
private static int transferEnergy(int energy, Map<IEnergyStorage, Integer> outputs) {
        int acceptedEnergy = 0;
        int energyToTransfer = energy;
        while (!outputs.isEmpty() && energyToTransfer >= outputs.size()) {
            int equalSplit = energyToTransfer / outputs.size();
            List<IEnergyStorage> outputsToRemove = new ArrayList<>();

            for (Entry<IEnergyStorage, Integer> output : outputs.entrySet()) {
                int actualSplit = equalSplit;
                if (output.getValue() < equalSplit) {
                    actualSplit = output.getValue();
                    outputsToRemove.add(output.getKey());
                }
                output.getKey().receiveEnergy(actualSplit, false);
                energyToTransfer -= actualSplit;
                acceptedEnergy += actualSplit;
            }

            outputsToRemove.forEach(outputs::remove);
        }

        return acceptedEnergy;
    }
/**
     * Handles the actual energy transfer process.
     * <p>
     * Automatically checks if the energy to transfer can be accepted by the possible outputs.
     * It will try to equally distribute it.
     *
     * @param energy  the energy to transfer
     * @param outputs the possible outputs
     * @return the accepted amount of energy
     */
Handles the actual energy transfer process.

Automatically checks if the energy to transfer can be accepted by the possible outputs.
It will try to equally distribute it.

@param energy  the energy to transfer
@param outputs the possible outputs
@return the accepted amount of energy
Handles the actual energy transfer process . Automatically checks if the energy to transfer can be accepted by the possible outputs . It will try to equally distribute it . @param energy the energy to transfer @param outputs the possible outputs @return the accepted amount of energy
private static int transferEnergy(int energy, Map<IEnergyStorage, Integer> outputs) {
        int acceptedEnergy = 0;
        int energyToTransfer = energy;
        while (!outputs.isEmpty() && energyToTransfer >= outputs.size()) {
            int equalSplit = energyToTransfer / outputs.size();
            List<IEnergyStorage> outputsToRemove = new ArrayList<>();
            for (Entry<IEnergyStorage, Integer> output : outputs.entrySet()) {
                int actualSplit = equalSplit;
                if (output.getValue() < equalSplit) {
                    actualSplit = output.getValue();
                    outputsToRemove.add(output.getKey());
                }
                output.getKey().receiveEnergy(actualSplit, false);
                energyToTransfer -= actualSplit;
                acceptedEnergy += actualSplit;
            }
            outputsToRemove.forEach(outputs::remove);
        }
        return acceptedEnergy;
    }
private static int transferEnergy ( int energy , Map < IEnergyStorage , Integer > outputs ) { int acceptedEnergy = 0 ; int energyToTransfer = energy ; while ( ! outputs . isEmpty ( ) && energyToTransfer >= outputs . size ( ) ) { int equalSplit = energyToTransfer / outputs . size ( ) ; List < IEnergyStorage > outputsToRemove = new ArrayList < > ( ) ; for ( Entry < IEnergyStorage , Integer > output : outputs . entrySet ( ) ) { int actualSplit = equalSplit ; if ( output . getValue ( ) < equalSplit ) { actualSplit = output . getValue ( ) ; outputsToRemove . add ( output . getKey ( ) ) ; } output . getKey ( ) . receiveEnergy ( actualSplit , false ) ; energyToTransfer -= actualSplit ; acceptedEnergy += actualSplit ; } outputsToRemove . forEach ( outputs :: remove ) ; } return acceptedEnergy ; }
Handles the actual energy transfer process.
Handles the actual energy transfer process .