List of usage examples for net.minecraftforge.energy IEnergyStorage getEnergyStored
int getEnergyStored();
From source file:com.buuz135.industrial.item.addon.EnergyFieldAddon.java
License:Open Source License
@Override public void addInformation(ItemStack stack, @Nullable World worldIn, List<String> tooltip, ITooltipFlag flagIn) {/*from w w w . j av a2s . c o m*/ super.addInformation(stack, worldIn, tooltip, flagIn); if (stack.hasCapability(CapabilityEnergy.ENERGY, null)) { IEnergyStorage storage = stack.getCapability(CapabilityEnergy.ENERGY, null); tooltip.add(new TextComponentTranslation("text.industrialforegoing.tooltip.energy_field_charge") .getUnformattedComponentText() + " " + new DecimalFormat().format(storage.getEnergyStored()) + " / " + new DecimalFormat().format(storage.getMaxEnergyStored())); if (getLinkedBlockPos(stack) != null) { BlockPos pos = getLinkedBlockPos(stack); tooltip.add(new TextComponentTranslation("text.industrialforegoing.tooltip.energy_field_linked") .getUnformattedComponentText() + " x=" + pos.getX() + " y=" + pos.getY() + " z=" + pos.getZ()); } else { tooltip.add( new TextComponentTranslation("text.industrialforegoing.tooltip.energy_field_right_click") .getUnformattedComponentText()); } } }
From source file:com.buuz135.industrial.item.addon.EnergyFieldAddon.java
License:Open Source License
@Override public double getDurabilityForDisplay(ItemStack stack) { if (stack.hasCapability(CapabilityEnergy.ENERGY, null)) { IEnergyStorage storage = stack.getCapability(CapabilityEnergy.ENERGY, null); if (storage != null) return (storage.getMaxEnergyStored() - storage.getEnergyStored()) / (double) storage.getMaxEnergyStored(); }/*from ww w .ja v a 2 s.c o m*/ return 0; }
From source file:com.buuz135.industrial.tile.CustomElectricMachine.java
License:Open Source License
@Override public void protectedUpdate() { super.protectedUpdate(); if (this.world.isRemote) return;/*from w w w . java2 s . c o m*/ if (world.getTotalWorldTime() % 2 == 0 && hasAddon(EnergyFieldAddon.class)) { ItemStack addon = getAddonStack(EnergyFieldAddon.class); if (addon.hasCapability(CapabilityEnergy.ENERGY, null)) { IEnergyStorage storage = addon.getCapability(CapabilityEnergy.ENERGY, null); storage.extractEnergy((int) this.getEnergyStorage().givePower(storage.extractEnergy(512, true)), false); BlockPos pos = ItemRegistry.energyFieldAddon.getLinkedBlockPos(addon); if (this.world.getBlockState(pos).getBlock() instanceof EnergyFieldProviderBlock && this.world.isAreaLoaded(pos, pos)) { EnergyFieldProviderTile tile = (EnergyFieldProviderTile) this.world.getTileEntity(pos); if (tile.getWorkingArea().grow(1) .contains(new Vec3d(this.pos.getX(), this.pos.getY(), this.pos.getZ()))) { float pull = tile.consumeWorkEnergy( Math.min(storage.getMaxEnergyStored() - storage.getEnergyStored(), 1000)); storage.receiveEnergy((int) pull, false); } } this.forceSync(); } } if (world.getTotalWorldTime() % 10 == 0 && this.getAddonItems() != null) { workTransferAddon(this, this.getAddonItems()); } }
From source file:com.elytradev.thermionics.transport.RFTransport.java
License:Open Source License
public static void diffuse(World world, BlockPos pos, IEnergyStorage host) { ArrayList<IEnergyStorage> consumers = getAdjacentStorage(world, pos); reorder(consumers); //We want to sample them in random order for (IEnergyStorage consumer : consumers) { //int totalEnergy = host.getEnergyStored() + consumer.getEnergyStored(); //float energyRatio = host.getMaxEnergyStored() / (float)consumer.getMaxEnergyStored(); float sourceLevel = host.getEnergyStored() / (float) host.getMaxEnergyStored(); float destLevel = consumer.getEnergyStored() / (float) consumer.getMaxEnergyStored(); if (sourceLevel > destLevel) { //Figure out how many quanta to transfer //int desiredSource = (int)(totalEnergy*energyRatio); //int desiredDest = (int)(totalEnergy/energyRatio); /*/*from w w w. ja v a2 s .co m*/ * Example: 2200 source, 1700 dest, capacity for each is 4000. * * totalEnergy: 3900 * energyRatio: 1.0f * sourceLevel: 0.55f * destLevel: 0.425f * availableQuanta: 500 / 2 - 1 = 249 * */ /* * Transmission data: * 0 blocks: 775.0 * 1 block : 393.6 * 2 blocks: 260.8 * 3 blocks: 196.6 * 4 blocks: 157.8 * 5 blocks: 131.8 */ int availableQuanta = ((int) ((sourceLevel - destLevel) * host.getMaxEnergyStored()) / 2); //trunc leaves fractional power differences where they are if (availableQuanta <= 0) continue; //StringBuilder debugString = new StringBuilder("RFTransfer: "); //debugString.append(host.getEnergyStored()); //debugString.append("("); debugString.append((int)(sourceLevel*100)); debugString.append("%) -> "); //debugString.append(consumer.getEnergyStored()); //debugString.append("("); debugString.append((int)(destLevel*100)); debugString.append("%) :"); //debugString.append(" req="); debugString.append(availableQuanta); int transferred = consumer.receiveEnergy(availableQuanta, true); if (transferred > 0) transferred = host.extractEnergy(transferred, false); //debugString.append(" rec="); debugString.append(transferred); //System.out.println(debugString.toString()); consumer.receiveEnergy(transferred, false); } } }
From source file:com.lothrazar.cyclicmagic.block.cable.TileEntityCableBase.java
License:Open Source License
private void moveEnergy(EnumFacing myFacingDir) { IEnergyStorage handlerHere = this.getCapability(CapabilityEnergy.ENERGY, myFacingDir); if (handlerHere.getEnergyStored() == 0) { return;/*from w ww. j a v a 2s . co m*/ } EnumFacing themFacingMe = myFacingDir.getOpposite(); BlockPos posTarget = pos.offset(myFacingDir); TileEntity tileTarget = world.getTileEntity(posTarget); if (tileTarget == null || tileTarget.hasCapability(CapabilityEnergy.ENERGY, themFacingMe) == false) { return; } IEnergyStorage handlerOutput = tileTarget.getCapability(CapabilityEnergy.ENERGY, themFacingMe); if (handlerHere != null && handlerOutput != null && handlerHere.canExtract() && handlerOutput.canReceive()) { //first simulate int drain = handlerHere.extractEnergy(MENERGY, true); if (drain > 0) { //now push it into output, but find out what was ACTUALLY taken int filled = handlerOutput.receiveEnergy(drain, false); //now actually drain that much from here handlerHere.extractEnergy(filled, false); if (filled > 0 && tileTarget instanceof TileEntityCableBase) { //TODO: not so compatible with other fluid systems. itl do i guess TileEntityCableBase cable = (TileEntityCableBase) tileTarget; if (cable.isEnergyPipe()) { cable.updateIncomingEnergyFace(themFacingMe); } } } } }
From source file:com.lothrazar.cyclicmagic.block.fishing.TileEntityFishing.java
License:Open Source License
private void damageTool() { ItemStack equip = this.getStackInSlot(SLOT_TOOL); if (equip.isEmpty()) { return;/*from ww w . ja v a 2 s . com*/ } if (equip.hasCapability(CapabilityEnergy.ENERGY, null)) { IEnergyStorage storage = equip.getCapability(CapabilityEnergy.ENERGY, null); if (storage != null) { storage.extractEnergy(ENERGY_PER_FISH, false); if (storage.getEnergyStored() <= 0) { this.sendOutputItem(equip); this.setInventorySlotContents(SLOT_TOOL, ItemStack.EMPTY); } return; } } else if (equip.getMaxDamage() > 0) { // -1 is unbreakable - EX Mystical Ag Supremium Fishing Rods equip.attemptDamageItem(1, getWorld().rand, null);//does respect unbreaking //IF enchanted and IF about to break, then spit it out int damageRem = equip.getMaxDamage() - equip.getItemDamage(); if (damageRem == 1 && EnchantmentHelper.getEnchantments(equip).size() > 0) { sendOutputItem(equip); this.setInventorySlotContents(SLOT_TOOL, ItemStack.EMPTY); } //otherwise we also make sure if its fullly damanged if (equip.getItemDamage() >= equip.getMaxDamage()) { this.setInventorySlotContents(SLOT_TOOL, ItemStack.EMPTY); } } }
From source file:com.lothrazar.cyclicmagic.block.screentarget.TileEntityScreenTarget.java
License:Open Source License
private String getEnergyString(TileEntity te, BlockPosDim target) { String energyStr;//from w w w . ja va 2s . com EnumFacing side = target.getSide() == null ? EnumFacing.UP : target.getSide(); if (te.hasCapability(CapabilityEnergy.ENERGY, side)) { IEnergyStorage energy = te.getCapability(CapabilityEnergy.ENERGY, side); //therefore energyStr = this.formatQuantity(energy.getEnergyStored(), energy.getMaxEnergyStored()); } else { energyStr = "--"; } return energyStr; }
From source file:com.lothrazar.cyclicmagic.gui.container.GuiBaseContainer.java
License:Open Source License
private String getFuelAmtDisplay() { IEnergyStorage energy = tile.getCapability(CapabilityEnergy.ENERGY, EnumFacing.UP); return energy.getEnergyStored() + "/" + energy.getMaxEnergyStored(); }
From source file:com.lothrazar.cyclicmagic.item.cannon.ItemProjectileCannon.java
License:Open Source License
@Override public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer player, EnumHand hand) { IEnergyStorage storage = player.getHeldItem(hand).getCapability(CapabilityEnergy.ENERGY, null); //HAS ENOUGH ENERGY? if (storage.getEnergyStored() < ENERGY_COST && ENERGY_COST > storage.extractEnergy(ENERGY_COST, true)) { UtilChat.sendStatusMessage(player, "cyclic.item.empty"); return new ActionResult<ItemStack>(EnumActionResult.PASS, player.getHeldItem(hand)); }/*from w w w . ja va2s .c o m*/ this.createBullet(world, player); UtilSound.playSound(player, player.getPosition(), SoundRegistry.fireball_staff_launch, SoundCategory.PLAYERS, 0.1F); player.swingArm(hand); //DRAIN ENERGY storage.extractEnergy(ENERGY_COST, false); return new ActionResult<ItemStack>(EnumActionResult.SUCCESS, player.getHeldItem(hand)); }
From source file:com.lothrazar.cyclicmagic.item.cannon.ItemProjectileCannon.java
License:Open Source License
@Override public double getDurabilityForDisplay(ItemStack item) { IEnergyStorage storage = item.getCapability(CapabilityEnergy.ENERGY, null); double energy = storage.getEnergyStored(); return 1 - energy / storage.getMaxEnergyStored(); }