Search in sources :

Example 1 with AttributeEnergy

use of mekanism.common.block.attribute.AttributeEnergy in project Mekanism by mekanism.

the class Factory method setMachineData.

private void setMachineData() {
    setFrom(origMachine, AttributeSound.class, AttributeFactoryType.class, AttributeUpgradeSupport.class);
    AttributeEnergy origEnergy = origMachine.get(AttributeEnergy.class);
    // TODO: Make this more readable
    add(new AttributeEnergy(origEnergy::getUsage, () -> origEnergy.getConfigStorage().multiply(0.5).max(origEnergy.getUsage()).multiply(((FactoryTier) get(AttributeTier.class).getTier()).processes)));
}
Also used : AttributeTier(mekanism.common.block.attribute.AttributeTier) AttributeEnergy(mekanism.common.block.attribute.AttributeEnergy)

Example 2 with AttributeEnergy

use of mekanism.common.block.attribute.AttributeEnergy in project Mekanism by mekanism.

the class MachineEnergyContainer method validateBlock.

public static AttributeEnergy validateBlock(TileEntityMekanism tile) {
    Objects.requireNonNull(tile, "Tile cannot be null");
    Block block = tile.getBlockType();
    if (!Attribute.has(block, AttributeEnergy.class)) {
        throw new IllegalArgumentException("Block provider must be an electric block");
    }
    return Attribute.get(block, AttributeEnergy.class);
}
Also used : Block(net.minecraft.block.Block) AttributeEnergy(mekanism.common.block.attribute.AttributeEnergy)

Example 3 with AttributeEnergy

use of mekanism.common.block.attribute.AttributeEnergy 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

AttributeEnergy (mekanism.common.block.attribute.AttributeEnergy)3 FloatingLongSupplier (mekanism.api.math.FloatingLongSupplier)1 AttributeTier (mekanism.common.block.attribute.AttributeTier)1 ItemCapabilityWrapper (mekanism.common.capabilities.ItemCapabilityWrapper)1 Block (net.minecraft.block.Block)1