コード例 #1
0
ファイル: PowerManager.java プロジェクト: nallar/QuarryPlus
 private static boolean useEnergy(
     PowerHandler pp, double BP, float H, double CSP, byte U, double CU) {
   float pw = (float) (BP * H * CSP / (U * CU + 1));
   if (pp.useEnergy(pw, pw, false) != pw) return false;
   pp.useEnergy(pw, pw, true);
   return true;
 }
コード例 #2
0
ファイル: PowerManager.java プロジェクト: nallar/QuarryPlus
 private static boolean useEnergy(
     PowerHandler pp,
     double BP1,
     long amount1,
     double BP2,
     long amount2,
     byte U,
     double CU1,
     double CU2) {
   float pw = (float) ((BP1 * amount1 / (U * CU1 + 1)) + (BP2 * amount2 / (U * CU2 + 1)));
   if (pp.useEnergy(pw, pw, false) != pw) return false;
   pp.useEnergy(pw, pw, true);
   return true;
 }
コード例 #3
0
ファイル: TileLaser.java プロジェクト: NervezXx/BuildCraft
  @Override
  public void updateEntity() {
    super.updateEntity();

    if (!CoreProxy.proxy.isSimulating(worldObj)) return;

    // If a gate disabled us, remove laser and do nothing.
    if (lastMode == ActionMachineControl.Mode.Off) {
      removeLaser();
      return;
    }

    // Check for available tables if none is linked to this laser.
    if (!isValidTable())
      if (canFindTable()) {
        findTable();
      }

    // If we still don't have a valid table or the existing has
    // become invalid, we disable the laser and do nothing.
    if (!isValidTable()) {
      removeLaser();
      return;
    }

    // Disable the laser and do nothing if no energy is available.
    if (powerHandler.getEnergyStored() == 0) {
      removeLaser();
      return;
    }

    // We have a table and can work, so we create a laser if
    // necessary.
    if (laser == null) {
      createLaser();
    }

    // We have a laser and may update it
    if (laser != null && canUpdateLaser()) {
      updateLaser();
    }

    // Consume power and transfer it to the table.
    float power = powerHandler.useEnergy(0, getMaxPowerSent(), true);
    laserTarget.receiveLaserEnergy(power);

    if (laser != null) {
      laser.pushPower(power);
    }

    onPowerSent(power);

    sendNetworkUpdate();
  }
コード例 #4
0
  public ItemStack checkExtractGeneric(
      IInventory inventory, boolean doRemove, ForgeDirection from, int[] slots) {
    for (int i : slots) {
      ItemStack slot = inventory.getStackInSlot(i);

      if (slot != null && slot.stackSize > 0 && canExtract(slot)) {
        if (doRemove) {
          return inventory.decrStackSize(i, (int) powerProvider.useEnergy(1, slot.stackSize, true));
        } else {
          return slot;
        }
      }
    }
    return null;
  }
コード例 #5
0
  @Override
  public void doWork(PowerHandler workProvider) {
    if (powerProvider.getEnergyStored() <= 0) return;

    World w = getWorld();

    int meta = w.getBlockMetadata(container.xCoord, container.yCoord, container.zCoord);

    if (meta > 5) return;

    Position pos =
        new Position(
            container.xCoord,
            container.yCoord,
            container.zCoord,
            ForgeDirection.VALID_DIRECTIONS[meta]);
    pos.moveForwards(1);
    int blockId = w.getBlockId((int) pos.x, (int) pos.y, (int) pos.z);
    TileEntity tile = w.getBlockTileEntity((int) pos.x, (int) pos.y, (int) pos.z);

    if (tile instanceof IInventory) {
      if (!PipeManager.canExtractItems(this, w, (int) pos.x, (int) pos.y, (int) pos.z)) return;

      IInventory inventory = (IInventory) tile;

      ItemStack extracted = checkExtract(inventory, true, pos.orientation.getOpposite());

      if (extracted == null || extracted.stackSize == 0) {
        powerProvider.useEnergy(1, 1, false);
        return;
      }

      Position entityPos =
          new Position(
              pos.x + 0.5,
              pos.y + CoreConstants.PIPE_MIN_POS,
              pos.z + 0.5,
              pos.orientation.getOpposite());
      entityPos.moveForwards(0.5);
      TravelingItem entity = new TravelingItem(entityPos.x, entityPos.y, entityPos.z, extracted);
      ((PipeTransportItems) transport).injectItem(entity, entityPos.orientation);
    }
  }
コード例 #6
0
ファイル: PowerManager.java プロジェクト: nallar/QuarryPlus
 private static float useEnergy(
     PowerHandler pp,
     double BP,
     byte U,
     double CU,
     byte F,
     double CF,
     boolean S,
     double CS,
     byte E,
     double CE) {
   double pwc = BP * Math.pow(CF, F) * Math.pow(CE, E) / (U * CU + 1);
   if (S) pwc *= CS;
   float pw = (float) pwc;
   pw = pp.useEnergy(0, pw, true);
   if (S) pwc = pw / CS;
   pwc /= Math.pow(CF, F);
   pwc *= U * CU + 1;
   return (float) pwc;
 }
コード例 #7
0
ファイル: PowerManager.java プロジェクト: nallar/QuarryPlus
 private static double useEnergy(PowerHandler pp, double D, double BP, byte U, double CU) {
   float pw = (float) Math.min(2 + pp.getEnergyStored() / 500, (D - 0.1) * BP / (U * CU + 1));
   pw = pp.useEnergy(pw, pw, true);
   return pw * (U * CU + 1) / BP + 0.1;
 }