net.minecraftforge.energy.IEnergyStorage Java Examples
The following examples show how to use
net.minecraftforge.energy.IEnergyStorage.
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: BatteryTileEntity.java From EmergingTechnology with MIT License | 6 votes |
private void spreadEnergy() { for (EnumFacing side : EnumFacing.VALUES) { if (side == getFacing()) { continue; } TileEntity tileEntity = world.getTileEntity(pos.offset(side)); if (tileEntity != null) { IEnergyStorage otherStorage = tileEntity.getCapability(CapabilityEnergy.ENERGY, side.getOpposite()); if (otherStorage != null) { if (otherStorage.canReceive()) { if (this.getEnergy() > 0) { int energySpread = otherStorage.receiveEnergy(this.getEnergy(), false); this.energyHandler.extractEnergy(energySpread, false); } } } } } }
Example #2
Source File: TileGenerator.java From YouTubeModdingTutorial with MIT License | 6 votes |
private void sendEnergy() { if (energyStorage.getEnergyStored() > 0) { for (EnumFacing facing : EnumFacing.VALUES) { TileEntity tileEntity = world.getTileEntity(pos.offset(facing)); if (tileEntity != null && tileEntity.hasCapability(CapabilityEnergy.ENERGY, facing.getOpposite())) { IEnergyStorage handler = tileEntity.getCapability(CapabilityEnergy.ENERGY, facing.getOpposite()); if (handler != null && handler.canReceive()) { int accepted = handler.receiveEnergy(energyStorage.getEnergyStored(), false); energyStorage.consumePower(accepted); if (energyStorage.getEnergyStored() <= 0) { break; } } } } markDirty(); } }
Example #3
Source File: UpgradeFueled.java From BetterChests with GNU Lesser General Public License v3.0 | 6 votes |
@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 #4
Source File: MiningGadget.java From MiningGadgets with MIT License | 5 votes |
@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 #5
Source File: MiningGadget.java From MiningGadgets with MIT License | 5 votes |
@Override public int getRGBDurabilityForDisplay(ItemStack stack) { IEnergyStorage energy = stack.getCapability(CapabilityEnergy.ENERGY, null).orElse(null); if (energy == null) return super.getRGBDurabilityForDisplay(stack); return MathHelper.hsvToRGB(Math.max(0.0F, (float) energy.getEnergyStored() / (float) energy.getMaxEnergyStored()) / 3.0F, 1.0F, 1.0F); }
Example #6
Source File: MiningGadget.java From MiningGadgets with MIT License | 5 votes |
public static boolean canMine(ItemStack tool) { IEnergyStorage energy = tool.getCapability(CapabilityEnergy.ENERGY, null).orElse(null); int cost = getEnergyCost(tool); if (MiningProperties.getRange(tool) == 3) cost = cost * 9; return energy.getEnergyStored() > cost; }
Example #7
Source File: UpgradeCharging.java From BetterChests with GNU Lesser General Public License v3.0 | 5 votes |
private static boolean chargeItem(ItemStack stack, IBetterChest chest) { IEnergyStorage storage = stack.getCapability(CapabilityEnergy.ENERGY, null); if (storage != null) { int maxCharge = chest.getEnergyStorage().getEnergyStored(); maxCharge = storage.receiveEnergy(maxCharge, false); if (maxCharge > 0) { chest.getEnergyStorage().extractEnergy(maxCharge, false); return true; } } return false; }
Example #8
Source File: MiningGadget.java From MiningGadgets with MIT License | 4 votes |
@Override public boolean showDurabilityBar(ItemStack stack) { IEnergyStorage energy = stack.getCapability(CapabilityEnergy.ENERGY, null).orElse(null); return (energy.getEnergyStored() < energy.getMaxEnergyStored()); }
Example #9
Source File: ItemHandler.java From BetterChests with GNU Lesser General Public License v3.0 | 4 votes |
@Override public String getToolTip(ItemStack stack) { IUpgradableBlock block = UpgradeHelper.INSTANCE.getInventory(stack, null); IEnergyStorage storage = block.getEnergyStorage(); return LocalizationHelper.localizeFormatted("betterchests:gui.upgrades.energy.tooltip", storage.getEnergyStored(), storage.getMaxEnergyStored()); }
Example #10
Source File: TileEntityUpgradableBlockBase.java From BetterChests with GNU Lesser General Public License v3.0 | 4 votes |
@Override public IEnergyStorage getEnergyStorage() { return energy; }
Example #11
Source File: BasicBagInventory.java From BetterChests with GNU Lesser General Public License v3.0 | 4 votes |
@Override public IEnergyStorage getEnergyStorage() { return this; }
Example #12
Source File: EnergyNetworkHelper.java From EmergingTechnology with MIT License | 3 votes |
private static void tryPushEnergyToTile(World world, BlockPos position, EnumFacing facing, GeneratorEnergyStorageHandler energyStorageHandler) { TileEntity tileEntity = world.getTileEntity(position); if (tileEntity == null) return; if (!tileEntity.hasCapability(CapabilityEnergy.ENERGY, facing)) return; IEnergyStorage energyStorage = tileEntity.getCapability(CapabilityEnergy.ENERGY, facing); if (energyStorage == null) return; int pushedEnergy = energyStorage.receiveEnergy(energyStorageHandler.getEnergyStored(), false); energyStorageHandler.extractEnergy(pushedEnergy, false); }
Example #13
Source File: IUpgradableBlock.java From BetterChests with GNU Lesser General Public License v3.0 | 2 votes |
/** * Returns the Energy Storage part of this Upgradable Block. * This is for internal use, so there is no transfer limit and it will fill/drain if there is space/energy * available. * @return The _internal EnergyStorage of this UpgradableBlock */ IEnergyStorage getEnergyStorage();