/** Recharges electric item. */
 @Override
 public void recharge(ItemStack itemStack) {
   if (itemStack != null) {
     if (itemStack.getItem() instanceof IItemElectric) {
       super.recharge(itemStack);
     } else if (Compatibility.isIndustrialCraft2Loaded()
         && itemStack.getItem() instanceof ISpecialElectricItem) {
       ISpecialElectricItem electricItem = (ISpecialElectricItem) itemStack.getItem();
       IElectricItemManager manager = electricItem.getManager(itemStack);
       float energy =
           Math.max(this.getProvide(ForgeDirection.UNKNOWN) * Compatibility.IC2_RATIO, 0);
       energy =
           manager.charge(itemStack, (int) (energy * Compatibility.TO_IC2_RATIO), 0, false, false)
               * Compatibility.IC2_RATIO;
       this.provideElectricity(energy, true);
     } else if (GCCoreCompatibilityManager.isTELoaded()
         && itemStack.getItem() instanceof IChargeableItem) {
       float accepted =
           ((IChargeableItem) itemStack.getItem())
               .receiveEnergy(
                   itemStack,
                   this.getProvide(ForgeDirection.UNKNOWN) * Compatibility.BC3_RATIO,
                   true);
       this.provideElectricity(accepted, true);
     }
   }
 }
Ejemplo n.º 2
0
  /**
   * Whether or not a defined deemed-electrical ItemStack can be outputted out of a slot. This puts
   * into account whether or not that slot is used for charging or discharging.
   *
   * @param itemstack - ItemStack to perform the check on
   * @param chargeSlot - whether or not the outputting slot is for charging or discharging
   * @return if the ItemStack can be outputted
   */
  public static boolean canBeOutputted(ItemStack itemstack, boolean chargeSlot) {
    if (itemstack.getItem() instanceof IEnergizedItem) {
      IEnergizedItem energized = (IEnergizedItem) itemstack.getItem();

      if (chargeSlot) {
        return energized.getEnergy(itemstack) == energized.getMaxEnergy(itemstack);
      } else {
        return energized.getEnergy(itemstack) == 0;
      }
    } else if (itemstack.getItem() instanceof IEnergyContainerItem) {
      IEnergyContainerItem energyContainer = (IEnergyContainerItem) itemstack.getItem();

      if (chargeSlot) {
        return energyContainer.receiveEnergy(itemstack, 1, true) > 0;
      } else {
        return energyContainer.extractEnergy(itemstack, 1, true) > 0;
      }
    } else if (itemstack.getItem() instanceof ISpecialElectricItem) {
      IElectricItemManager manager =
          ((ISpecialElectricItem) itemstack.getItem()).getManager(itemstack);

      if (manager != null) {
        if (chargeSlot) {
          return manager.charge(itemstack, 1, 3, true, true) > 0;
        } else {
          return manager.discharge(itemstack, 1, 3, true, true, true) > 0;
        }
      }
    }

    return true;
  }