TechReborn / RebornCore

Reborn Core is a library used for many of the Tech Reborn team's mods, including Tech Reborn, Quantum Storage, Fluxed Redstone, Hardcore Map Reset, and many more.
MIT License
44 stars 51 forks source link

Add implementations in ExternalPowerSystems for chargeItem and requestEnergyFromArmor #98

Closed coderbot16 closed 5 years ago

coderbot16 commented 5 years ago

Looks like I forgot these in the previous PR. Convenience functions in line with the other implementations provided in ExternalPowerSystems.

modmuss50 commented 5 years ago

Is it worth checking ExternalPowerManager.isPoweredItem before charging the item?

Would be quite easy to add and may save some time / prevent issues if not checked in the ExternalPowerManager

coderbot16 commented 5 years ago

Seems easy enough, I can add that. Would avoid potential bugs in other ExternalPowerManager implementations.

coderbot16 commented 5 years ago

Alright, I added checks to dischargeItem and chargeItem. I didn't add any checks to requestEnergyFromArmor since the manager is responsible for finding and discharging the items itself, and ExternalPowerSystems doesn't know what items the implementation will be drawing energy from.

coderbot16 commented 5 years ago

Also, I'll keep the isPoweredItem checks in the ExternalPowerManager implementations since it is possible to access them without going through ExternalPowerSystems methods.

modmuss50 commented 5 years ago

Logic looks good, how ever this can be done in a cleaner way using filter

Here is an example:

public static void chargeItem(TilePowerAcceptor tilePowerAcceptor, ItemStack stack){
    externalPowerHandlerList.stream()
        .filter(externalPowerManager -> externalPowerManager.isPoweredItem(stack))
        .forEach(externalPowerManager -> externalPowerManager.chargeItem(tilePowerAcceptor, stack));
}
coderbot16 commented 5 years ago

Ah yes, I probably should have done that since I'm already used to the Rust iterator APIs :P - will fix

coderbot16 commented 5 years ago

Alright, the checks now properly utilize Stream::filter.

modmuss50 commented 5 years ago

Looks good, thanks