@Override
  public void updateEntity() {
    super.updateEntity();

    // Register to the IC2 Network
    if (!this.worldObj.isRemote) {
      if (!this.isAddedToEnergyNet) {
        this.initIC();
      }

      if (this.bcPowerHandler == null) {
        this.initBuildCraft();
      }

      if (Compatibility.isBuildcraftLoaded()) {
        PowerHandler handler = (PowerHandler) this.bcPowerHandler;

        if (handler.getEnergyStored() > 0) {
          /** Cheat BuildCraft powerHandler and always empty energy inside of it. */
          this.receiveElectricity(handler.getEnergyStored() * Compatibility.BC3_RATIO, true);
          handler.setEnergy(0);
        }
      }
    }
  }
Beispiel #2
0
 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;
 }
  public PipeItemsAdvancedWood(int itemID) {
    super(new PipeTransportAdvancedWood(), itemID);
    transport = (PipeTransportAdvancedWood) super.transport;

    powerProvider = new PowerHandler(this, Type.MACHINE);
    powerProvider.configure(1, 64.1f, 1, 64.1f);
    powerProvider.configurePowerPerdition(0, 0);
  }
Beispiel #4
0
  @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();
  }
Beispiel #5
0
 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;
 }
Beispiel #6
0
  @Override
  public void readFromNBT(NBTTagCompound nbttagcompound) {
    super.readFromNBT(nbttagcompound);

    powerHandler.readFromNBT(nbttagcompound);
    initPowerProvider();
  }
  @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);
    }
  }
  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;
  }
Beispiel #9
0
 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;
 }
Beispiel #10
0
 private static void configure15(
     PowerHandler pp,
     double CE,
     byte E,
     byte U,
     double CU,
     double NR,
     double XR,
     double BP,
     double MS,
     byte pump) {
   pp.configure(
       (float) (NR / (U * CU + 1)),
       (float) (XR * Math.pow(CE, E) / (U * CU + 1)),
       (float) (BP * 1.5 * Math.pow(CE, E) / (U * CU + 1)),
       (float)
           (MS * Math.pow(CE, E) / (U * CU + 1)
               + (pump > 0
                   ? ((65536 * PL_BP / ((pump * PL_CU + 1)))
                       + (1020 * PF_BP / ((pump * PF_CU + 1))))
                   : 0)));
 }
Beispiel #11
0
 private void initPowerProvider() {
   powerHandler.configure(25, 150, 25, 1000);
   powerHandler.setPerdition(PERDITION);
 }
Beispiel #12
0
  @Override
  public void writeToNBT(NBTTagCompound nbttagcompound) {
    super.writeToNBT(nbttagcompound);

    powerHandler.writeToNBT(nbttagcompound);
  }
Beispiel #13
0
 @Override
 public PowerReceiver getPowerReceiver(ForgeDirection side) {
   return powerHandler.getPowerReceiver();
 }
Beispiel #14
0
 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;
 }
Beispiel #15
0
 static void configure0(PowerHandler pp) {
   pp.configure(0, 0, 0, Float.MAX_VALUE);
 }