示例#1
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;
  }
示例#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);
        }
      }
    }
  }
示例#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;
        }
      }
    }
  }
示例#4
0
  /**
   * Universally charges an item, and updates the TileEntity's energy level.
   *
   * @param slotID - ID of the slot of which to discharge
   * @param storer - TileEntity the item is being discharged in
   */
  public static void charge(int slotID, IStrictEnergyStorage storer) {
    IInventory inv = (TileEntityContainerBlock) storer;

    if (inv.getStackInSlot(slotID) != null && storer.getEnergy() > 0) {
      if (inv.getStackInSlot(slotID).getItem() instanceof IEnergizedItem) {
        storer.setEnergy(
            storer.getEnergy()
                - EnergizedItemManager.charge(inv.getStackInSlot(slotID), storer.getEnergy()));
      } else if (MekanismUtils.useIC2()
          && inv.getStackInSlot(slotID).getItem() instanceof IElectricItem) {
        double sent =
            ElectricItem.manager.charge(
                    inv.getStackInSlot(slotID),
                    (int) (storer.getEnergy() * general.TO_IC2),
                    4,
                    true,
                    false)
                * general.FROM_IC2;
        storer.setEnergy(storer.getEnergy() - sent);
      } 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.getMaxEnergyStored(itemStack) - item.getEnergyStored(itemStack)));
        int toTransfer =
            (int) Math.round(Math.min(itemEnergy, (storer.getEnergy() * general.TO_RF)));

        storer.setEnergy(
            storer.getEnergy()
                - (item.receiveEnergy(itemStack, toTransfer, false) * general.FROM_RF));
      }
    }
  }
示例#5
0
  /**
   * Universally charges an item, and updates the TileEntity's energy level.
   *
   * @param slotID - ID of the slot of which to discharge
   * @param storer - TileEntity the item is being discharged in
   */
  public static void charge(int slotID, TileEntityElectricBlock storer) {
    if (storer.inventory[slotID] != null && storer.getEnergy() > 0) {
      if (storer.inventory[slotID].getItem() instanceof IEnergizedItem) {
        storer.setEnergy(
            storer.getEnergy()
                - EnergizedItemManager.charge(storer.inventory[slotID], storer.getEnergy()));
      } else if (Mekanism.hooks.IC2Loaded
          && storer.inventory[slotID].getItem() instanceof IElectricItem) {
        double sent =
            ElectricItem.manager.charge(
                    storer.inventory[slotID],
                    (int) (storer.getEnergy() * Mekanism.TO_IC2),
                    4,
                    true,
                    false)
                * Mekanism.FROM_IC2;
        storer.setEnergy(storer.getEnergy() - sent);
      } 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.getMaxEnergyStored(itemStack) - item.getEnergyStored(itemStack)));
        int toTransfer =
            (int) Math.round(Math.min(itemEnergy, (storer.getEnergy() * Mekanism.TO_TE)));

        storer.setEnergy(
            storer.getEnergy()
                - (item.receiveEnergy(itemStack, toTransfer, false) * Mekanism.FROM_TE));
      }
    }
  }