コード例 #1
0
  @Override
  public boolean produceUE(ForgeDirection outputDirection) {
    if (!this.worldObj.isRemote
        && outputDirection != null
        && outputDirection != ForgeDirection.UNKNOWN) {
      float provide = this.getProvide(outputDirection);

      if (provide > 0) {
        TileEntity outputTile =
            VectorHelper.getConnectorFromSide(this.worldObj, new Vector3(this), outputDirection);
        IElectricityNetwork outputNetwork =
            ElectricityHelper.getNetworkFromTileEntity(outputTile, outputDirection);
        if (outputNetwork != null) {
          ElectricityPack powerRequest = outputNetwork.getRequest(this);

          if (powerRequest.getWatts() > 0) {
            ElectricityPack sendPack =
                ElectricityPack.min(
                    ElectricityPack.getFromWatts(this.getEnergyStored(), this.getVoltage()),
                    ElectricityPack.getFromWatts(provide, this.getVoltage()));
            float rejectedPower = outputNetwork.produce(sendPack, this);
            this.provideElectricity(sendPack.getWatts() - rejectedPower, true);
            return true;
          }
        } else if (outputTile instanceof IElectrical) {
          float requestedEnergy =
              ((IElectrical) outputTile).getRequest(outputDirection.getOpposite());

          if (requestedEnergy > 0) {
            ElectricityPack sendPack =
                ElectricityPack.min(
                    ElectricityPack.getFromWatts(this.getEnergyStored(), this.getVoltage()),
                    ElectricityPack.getFromWatts(provide, this.getVoltage()));
            float acceptedEnergy =
                ((IElectrical) outputTile)
                    .receiveElectricity(outputDirection.getOpposite(), sendPack, true);
            this.setEnergyStored(this.getEnergyStored() - acceptedEnergy);
            return true;
          }
        }
      }
    }

    return false;
  }
コード例 #2
0
  @Override
  public int charge(ItemStack stack, int energyInput) {
    IItemElectric item = (IItemElectric) Item.itemsList[stack.itemID];

    double wattsInput = energyInput / getPowerSystem().getInternalEnergyPerOutput();

    ElectricityPack consumed = item.onReceive(ElectricityPack.getFromWatts(wattsInput, 120), stack);

    return MathHelper.floor_double(
        (wattsInput - consumed.getWatts()) * getPowerSystem().getInternalEnergyPerOutput());
  }
コード例 #3
0
  @RuntimeInterface(clazz = "ic2.api.energy.tile.IEnergySink", modID = "IC2")
  public double injectEnergyUnits(ForgeDirection direction, double amount) {
    if (this.getInputDirections().contains(direction)) {
      float convertedEnergy = (float) (amount * Compatibility.IC2_RATIO);
      ElectricityPack toSend = ElectricityPack.getFromWatts(convertedEnergy, this.getVoltage());
      float receive = this.receiveElectricity(direction, toSend, true);

      // Return the difference, since injectEnergy returns left over
      // energy, and
      // receiveElectricity returns energy used.
      return Math.round(amount - receive * Compatibility.TO_IC2_RATIO);
    }

    return amount;
  }