Search in sources :

Example 1 with BasicEnergyContainer

use of mekanism.common.capabilities.energy.BasicEnergyContainer in project Mekanism by mekanism.

the class StorageUtils method getFilledEnergyVariant.

public static ItemStack getFilledEnergyVariant(ItemStack toFill, FloatingLong capacity) {
    // Manually handle this as capabilities are not necessarily loaded yet (at least not on the first call to this, which is made via fillItemGroup)
    BasicEnergyContainer container = BasicEnergyContainer.create(capacity, null);
    container.setEnergy(capacity);
    ItemDataUtils.setList(toFill, NBTConstants.ENERGY_CONTAINERS, DataHandlerUtils.writeContainers(Collections.singletonList(container)));
    // The item is now filled return it for convenience
    return toFill;
}
Also used : BasicEnergyContainer(mekanism.common.capabilities.energy.BasicEnergyContainer)

Example 2 with BasicEnergyContainer

use of mekanism.common.capabilities.energy.BasicEnergyContainer in project Mekanism by mekanism.

the class StorageUtils method getStoredEnergyFromNBT.

/**
 * Gets the energy if one is stored from an item's container going off the basis there is a single energy container. This is for cases when we may not actually have
 * an energy handler attached to our item, but it may have stored data in its container from when it was a block
 */
public static FloatingLong getStoredEnergyFromNBT(ItemStack stack) {
    BasicEnergyContainer container = BasicEnergyContainer.create(FloatingLong.MAX_VALUE, null);
    DataHandlerUtils.readContainers(Collections.singletonList(container), ItemDataUtils.getList(stack, NBTConstants.ENERGY_CONTAINERS));
    return container.getEnergy();
}
Also used : BasicEnergyContainer(mekanism.common.capabilities.energy.BasicEnergyContainer)

Aggregations

BasicEnergyContainer (mekanism.common.capabilities.energy.BasicEnergyContainer)2