Closed coderbot16 closed 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
Seems easy enough, I can add that. Would avoid potential bugs in other ExternalPowerManager implementations.
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.
Also, I'll keep the isPoweredItem checks in the ExternalPowerManager implementations since it is possible to access them without going through ExternalPowerSystems methods.
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));
}
Ah yes, I probably should have done that since I'm already used to the Rust iterator APIs :P - will fix
Alright, the checks now properly utilize Stream::filter.
Looks good, thanks
Looks like I forgot these in the previous PR. Convenience functions in line with the other implementations provided in ExternalPowerSystems.