public void discharge(ItemStack itemStack) {
    if (itemStack != null) {
      Item item = itemStack.getItem();
      float energyToDischarge = this.getRequest(null);

      if (item instanceof IItemElectric) {
        this.storage.receiveEnergyGC(
            ElectricItemHelper.dischargeItem(itemStack, energyToDischarge));
      }
      //            else if (EnergyConfigHandler.isRFAPILoaded() && item instanceof
      // IEnergyContainerItem)
      //            {
      //
      // this.storage.receiveEnergyGC(((IEnergyContainerItem)item).extractEnergy(itemStack, (int)
      // (energyToDischarge / EnergyConfigHandler.RF_RATIO), false) * EnergyConfigHandler.RF_RATIO);
      //            }
      else if (EnergyConfigHandler.isMekanismLoaded()
          && item instanceof IEnergizedItem
          && ((IEnergizedItem) item).canSend(itemStack)) {
        this.storage.receiveEnergyGC(
            (float)
                    EnergizedItemManager.discharge(
                        itemStack, energyToDischarge / EnergyConfigHandler.MEKANISM_RATIO)
                * EnergyConfigHandler.MEKANISM_RATIO);
      } else if (EnergyConfigHandler.isIndustrialCraft2Loaded()) {
        if (item instanceof ISpecialElectricItem) {
          ISpecialElectricItem electricItem = (ISpecialElectricItem) item;
          if (electricItem.canProvideEnergy(itemStack)) {
            double energyDischargeIC2 = energyToDischarge / EnergyConfigHandler.IC2_RATIO;
            double result =
                electricItem
                    .getManager(itemStack)
                    .discharge(itemStack, energyDischargeIC2, 4, false, false, false);
            float energyDischarged = (float) result * EnergyConfigHandler.IC2_RATIO;
            this.storage.receiveEnergyGC(energyDischarged);
          }
        } else if (item instanceof IElectricItem) {
          IElectricItem electricItem = (IElectricItem) item;
          if (electricItem.canProvideEnergy(itemStack)) {
            double energyDischargeIC2 = energyToDischarge / EnergyConfigHandler.IC2_RATIO;
            double result =
                ElectricItem.manager.discharge(
                    itemStack, energyDischargeIC2, 4, false, false, false);
            float energyDischarged = (float) result * EnergyConfigHandler.IC2_RATIO;
            this.storage.receiveEnergyGC(energyDischarged);
          }
        }
      }
      //			else if (GCCoreCompatibilityManager.isTELoaded() && itemStack.getItem() instanceof
      // IEnergyContainerItem)
      //			{
      //				float given = ((IEnergyContainerItem) itemStack.getItem()).extractEnergy(itemStack,
      // (int) Math.floor(this.getRequest(EnumFacing.UNKNOWN) * EnergyConfigHandler.TO_TE_RATIO),
      // false);
      //				this.receiveElectricity(given * EnergyConfigHandler.TE_RATIO, true);
      //			}
    }
  }
Example #2
0
  /**
   * Universally discharges an item, and updates the TileEntity's energy level.
   *
   * @param slotID - ID of the slot of which to charge
   * @param storer - TileEntity the item is being charged in
   */
  public static void discharge(int slotID, IStrictEnergyStorage storer) {
    IInventory inv = (TileEntityContainerBlock) storer;

    if (inv.getStackInSlot(slotID) != null && storer.getEnergy() < storer.getMaxEnergy()) {
      if (inv.getStackInSlot(slotID).getItem() instanceof IEnergizedItem) {
        storer.setEnergy(
            storer.getEnergy()
                + EnergizedItemManager.discharge(
                    inv.getStackInSlot(slotID), storer.getMaxEnergy() - storer.getEnergy()));
      } else if (MekanismUtils.useIC2()
          && inv.getStackInSlot(slotID).getItem() instanceof IElectricItem) {
        IElectricItem item = (IElectricItem) inv.getStackInSlot(slotID).getItem();

        if (item.canProvideEnergy(inv.getStackInSlot(slotID))) {
          double gain =
              ElectricItem.manager.discharge(
                      inv.getStackInSlot(slotID),
                      (int) ((storer.getMaxEnergy() - storer.getEnergy()) * general.TO_IC2),
                      4,
                      true,
                      true,
                      false)
                  * general.FROM_IC2;
          storer.setEnergy(storer.getEnergy() + gain);
        }
      } else if (MekanismUtils.useRF()
          && inv.getStackInSlot(slotID).getItem() instanceof IEnergyContainerItem) {
        ItemStack itemStack = inv.getStackInSlot(slotID);
        IEnergyContainerItem item = (IEnergyContainerItem) inv.getStackInSlot(slotID).getItem();

        int itemEnergy =
            (int)
                Math.round(
                    Math.min(
                        Math.sqrt(item.getMaxEnergyStored(itemStack)),
                        item.getEnergyStored(itemStack)));
        int toTransfer =
            (int)
                Math.round(
                    Math.min(
                        itemEnergy,
                        ((storer.getMaxEnergy() - storer.getEnergy()) * general.TO_RF)));

        storer.setEnergy(
            storer.getEnergy()
                + (item.extractEnergy(itemStack, toTransfer, false) * general.FROM_RF));
      } else if (inv.getStackInSlot(slotID).getItem() == Items.REDSTONE
          && storer.getEnergy() + general.ENERGY_PER_REDSTONE <= storer.getMaxEnergy()) {
        storer.setEnergy(storer.getEnergy() + general.ENERGY_PER_REDSTONE);
        inv.getStackInSlot(slotID).stackSize--;

        if (inv.getStackInSlot(slotID).stackSize <= 0) {
          inv.setInventorySlotContents(slotID, null);
        }
      }
    }
  }
Example #3
0
  /**
   * Universally discharges an item, and updates the TileEntity's energy level.
   *
   * @param slotID - ID of the slot of which to charge
   * @param storer - TileEntity the item is being charged in
   */
  public static void discharge(int slotID, TileEntityElectricBlock storer) {
    if (storer.inventory[slotID] != null && storer.getEnergy() < storer.getMaxEnergy()) {
      if (storer.inventory[slotID].getItem() instanceof IEnergizedItem) {
        storer.setEnergy(
            storer.getEnergy()
                + EnergizedItemManager.discharge(
                    storer.inventory[slotID], storer.getMaxEnergy() - storer.getEnergy()));
      } else if (Mekanism.hooks.IC2Loaded
          && storer.inventory[slotID].getItem() instanceof IElectricItem) {
        IElectricItem item = (IElectricItem) storer.inventory[slotID].getItem();

        if (item.canProvideEnergy(storer.inventory[slotID])) {
          double gain =
              ElectricItem.manager.discharge(
                      storer.inventory[slotID],
                      (int) ((storer.getMaxEnergy() - storer.getEnergy()) * Mekanism.TO_IC2),
                      4,
                      true,
                      false)
                  * Mekanism.FROM_IC2;
          storer.setEnergy(storer.getEnergy() + gain);
        }
      } else if (storer.inventory[slotID].getItem() instanceof IEnergyContainerItem) {
        ItemStack itemStack = storer.inventory[slotID];
        IEnergyContainerItem item = (IEnergyContainerItem) storer.inventory[slotID].getItem();

        int itemEnergy =
            (int)
                Math.round(
                    Math.min(
                        Math.sqrt(item.getMaxEnergyStored(itemStack)),
                        item.getEnergyStored(itemStack)));
        int toTransfer =
            (int)
                Math.round(
                    Math.min(
                        itemEnergy,
                        ((storer.getMaxEnergy() - storer.getEnergy()) * Mekanism.TO_TE)));

        storer.setEnergy(
            storer.getEnergy()
                + (item.extractEnergy(itemStack, toTransfer, false) * Mekanism.FROM_TE));
      } else if (storer.inventory[slotID].itemID == Item.redstone.itemID
          && storer.getEnergy() + Mekanism.ENERGY_PER_REDSTONE <= storer.getMaxEnergy()) {
        storer.setEnergy(storer.getEnergy() + Mekanism.ENERGY_PER_REDSTONE);
        storer.inventory[slotID].stackSize--;

        if (storer.inventory[slotID].stackSize <= 0) {
          storer.inventory[slotID] = null;
        }
      }
    }
  }