Java Code Examples for net.minecraftforge.energy.IEnergyStorage#getMaxEnergyStored()

The following examples show how to use net.minecraftforge.energy.IEnergyStorage#getMaxEnergyStored() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: UpgradeFueled.java    From BetterChests with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public void update(IUpgradableBlock chest, ItemStack stack) {
	if (UpgradeHelper.INSTANCE.getFrequencyTick(chest, stack, 64) != 0) {
		return;
	}
	IEnergyStorage storage = chest.getEnergyStorage();
	if (storage.getEnergyStored() >= storage.getMaxEnergyStored()) {
		return;
	}

	IBetterChest inv = (IBetterChest) chest;
	IFilter filter = inv.getFilterFor(stack);

	int slot = InvUtil.findInInvInternal(inv, null, test -> TileEntityFurnace.getItemBurnTime(test) > 0 && filter.matchesStack(test));
	if (slot != -1) {
		ItemStack current = inv.getStackInSlot(slot);
		int provided = TileEntityFurnace.getItemBurnTime(current) * Config.INSTANCE.energyFueled;
		if (storage.receiveEnergy(provided, true) == provided) {
			storage.receiveEnergy(provided, false);
			current.setCount(current.getCount() - 1);
			inv.markDirty();
		}
	}
}
 
Example 2
Source File: MiningGadget.java    From MiningGadgets with MIT License 5 votes vote down vote up
@Override
public double getDurabilityForDisplay(ItemStack stack) {
    IEnergyStorage energy = stack.getCapability(CapabilityEnergy.ENERGY, null).orElse(null);
    if (energy == null)
        return 0;

    return 1D - (energy.getEnergyStored() / (double) energy.getMaxEnergyStored());
}
 
Example 3
Source File: MiningGadget.java    From MiningGadgets with MIT License 4 votes vote down vote up
@Override
public boolean showDurabilityBar(ItemStack stack) {
    IEnergyStorage energy = stack.getCapability(CapabilityEnergy.ENERGY, null).orElse(null);
    return (energy.getEnergyStored() < energy.getMaxEnergyStored());
}