Search in sources :

Example 1 with FloatingLongSupplier

use of mekanism.api.math.FloatingLongSupplier in project Mekanism by mekanism.

the class ItemBlockMachine method initCapabilities.

@Override
public ICapabilityProvider initCapabilities(ItemStack stack, CompoundNBT nbt) {
    if (Attribute.has(getBlock(), AttributeEnergy.class)) {
        AttributeEnergy attributeEnergy = Attribute.get(getBlock(), AttributeEnergy.class);
        FloatingLongSupplier maxEnergy;
        if (Attribute.has(getBlock(), AttributeUpgradeSupport.class)) {
            // If our block supports upgrades, make a more dynamically updating cache for our item's max energy
            maxEnergy = new UpgradeBasedFloatingLongCache(stack, attributeEnergy::getStorage);
        } else {
            // Otherwise, just return that the max is what the base max is
            maxEnergy = attributeEnergy::getStorage;
        }
        return new ItemCapabilityWrapper(stack, RateLimitEnergyHandler.create(maxEnergy, BasicEnergyContainer.manualOnly, BasicEnergyContainer.alwaysTrue));
    }
    return super.initCapabilities(stack, nbt);
}
Also used : FloatingLongSupplier(mekanism.api.math.FloatingLongSupplier) ItemCapabilityWrapper(mekanism.common.capabilities.ItemCapabilityWrapper) AttributeEnergy(mekanism.common.block.attribute.AttributeEnergy)

Aggregations

FloatingLongSupplier (mekanism.api.math.FloatingLongSupplier)1 AttributeEnergy (mekanism.common.block.attribute.AttributeEnergy)1 ItemCapabilityWrapper (mekanism.common.capabilities.ItemCapabilityWrapper)1