コード例 #1
0
ファイル: Compactor.java プロジェクト: MonsieurWTF/FactoryMod
  public List<InteractionResponse> getChestResponse() {
    List<InteractionResponse> responses = new ArrayList<InteractionResponse>();
    String status = active ? "On" : "Off";
    int maxRepair = getMaxRepair();
    boolean maintenanceActive = maxRepair != 0;
    String response = "Current costs are : "; // the response specific to the mode.
    if (mode.equals(CompactorMode.REPAIR)) {
      response += getRepairs().toString();
    } else if (mode.equals(CompactorMode.COMPACT)) {
      ItemList<NamedItemStack> inputs = getInputs();
      response += (inputs.isEmpty() ? "Nothing to compact." : inputs.toString());
    } else if (mode.equals(CompactorMode.DECOMPACT)) {
      ItemList<NamedItemStack> inputs = getInputs();
      response +=
          (inputs.isEmpty()
              ? "Nothing to decompact."
              : inputs.toString() + " " + cp.getCompactLore());
    }

    String percentDone =
        status.equals("On")
            ? " - " + Math.round(currentProductionTimer * 100 / getProductionTime()) + "% done."
            : "";
    int health =
        (!maintenanceActive) ? 100 : (int) Math.round(100 * (1 - currentRepair / (maxRepair)));
    responses.add(
        new InteractionResponse(
            InteractionResult.SUCCESS,
            cp.getName() + ": " + status + " with " + String.valueOf(health) + "% health."));
    responses.add(
        new InteractionResponse(
            InteractionResult.SUCCESS, "Current mode: " + mode.getDescription()));
    responses.add(new InteractionResponse(InteractionResult.SUCCESS, response));
    responses.add(new InteractionResponse(InteractionResult.SUCCESS, percentDone));

    if (!getRepairs().isEmpty() && maintenanceActive && mode == CompactorMode.REPAIR) {
      int amountAvailable = getRepairs().amountAvailable(getInventory());
      int amountRepaired =
          amountAvailable > currentRepair ? (int) Math.ceil(currentRepair) : amountAvailable;
      int percentRepaired = (int) (((double) amountRepaired) / maxRepair * 100);
      responses.add(
          new InteractionResponse(
              InteractionResult.SUCCESS,
              "Will repair "
                  + String.valueOf(percentRepaired)
                  + "% of the factory with "
                  + getRepairs().getMultiple(amountRepaired).toString()
                  + "."));
    }

    return responses;
  }
コード例 #2
0
  /**
   * Returns either a success or error message. Called by the blockListener when a player left
   * clicks the powerSourceLocation with the InteractionMaterial
   */
  public List<InteractionResponse> togglePower() {
    List<InteractionResponse> response = new ArrayList<InteractionResponse>();
    // if the factory is turned off
    if (!active) {
      // if the factory isn't broken or the current recipe can repair it
      if (!isBroken() || isRepairing()) {
        // is there fuel enough for at least once energy cycle?
        if (isFuelAvailable()) {
          // are there enough materials for the current recipe in the chest?
          if (checkHasMaterials()) {
            // turn the factory on
            powerOn();
            // return a success message
            response.add(new InteractionResponse(InteractionResult.SUCCESS, "Factory activated!"));
            return response;
          }
          // there are not enough materials for the recipe!
          else {
            // return a failure message, containing which materials are needed for the recipe
            // [Requires the following: Amount Name, Amount Name.]
            // [Requires one of the following: Amount Name, Amount Name.]

            ItemList<NamedItemStack> needAll = getAllInputs();
            needAll.addAll(getAllInputs().getDifference(getInventory()));
            if (!needAll.isEmpty()) {
              response.add(
                  new InteractionResponse(
                      InteractionResult.FAILURE,
                      "You need all of the following: " + needAll.toString() + "."));
            }
            return response;
          }
        }
        // if there isn't enough fuel for at least one energy cycle
        else {
          // return a error message
          int multiplesRequired = (int) Math.ceil(getProductionTime() / (double) getEnergyTime());
          response.add(
              new InteractionResponse(
                  InteractionResult.FAILURE,
                  "Factory is missing fuel! ("
                      + getFuel().getMultiple(multiplesRequired).toString()
                      + ")"));
          return response;
        }
      } else {
        response.add(
            new InteractionResponse(InteractionResult.FAILURE, "Factory is in disrepair!"));
        return response;
      }
    }
    // if the factory is on already
    else {
      // turn the factory off
      powerOff();
      // return success message
      response.add(
          new InteractionResponse(InteractionResult.FAILURE, "Factory has been deactivated!"));
      return response;
    }
  }
コード例 #3
0
  @Override
  public List<InteractionResponse> togglePower() {
    log.info("Repair factory at " + this.factoryLocation.toString() + " power toggle attempt");
    List<InteractionResponse> response = new ArrayList<InteractionResponse>();
    // if the factory is turned off
    if (!active) {
      // if the factory isn't broken or the current recipe can repair it
      if (!isBroken() || isRepairing()) {
        // is there fuel enough for at least once energy cycle?
        if (isFuelAvailable()) {
          // are there enough materials for the current recipe in the chest?
          if (checkHasMaterials()) {
            // turn the factory on
            powerOn();
            // return a success message
            response.add(new InteractionResponse(InteractionResult.SUCCESS, "Factory activated!"));
            return response;
          } else { // there are not enough materials for the recipe!
            // return a failure message, containing which materials are needed for the recipe
            // [Requires the following: Amount Name, Amount Name.]
            // [Requires one of the following: Amount Name, Amount Name.]

            ItemList<NamedItemStack> needAll = new ItemList<NamedItemStack>();
            ItemList<NamedItemStack> allInputs = null;

            if (mode.equals(RepairFactoryMode.REPAIR)) {
              allInputs = rfp.getRepairMaterials();
            } else if (mode.equals(RepairFactoryMode.RESET_ITEMS)) {
              allInputs = rfp.getRecipeMaterials();
            }

            needAll.addAll(allInputs.getDifference(getInventory()));
            if (!needAll.isEmpty()) {
              response.add(
                  new InteractionResponse(
                      InteractionResult.FAILURE,
                      "You need all of the following: " + needAll.toString() + "."));
            } else if (allInputs == null || allInputs.isEmpty()) {
              System.out.println(
                  "getAllInputs() returned null or empty; recipe is returning no expectation of input!");
            }
            return response;
          }
        } else { // if there isn't enough fuel for at least one energy cycle
          // return a error message
          int multiplesRequired = (int) Math.ceil(getProductionTime() / (double) getEnergyTime());
          response.add(
              new InteractionResponse(
                  InteractionResult.FAILURE,
                  "Factory is missing fuel! ("
                      + getFuel().getMultiple(multiplesRequired).toString()
                      + ")"));
          return response;
        }
      } else {
        response.add(
            new InteractionResponse(InteractionResult.FAILURE, "Factory is in disrepair!"));
        return response;
      }
    } else { // if the factory is on already
      // turn the factory off
      powerOff();
      // return success message
      response.add(
          new InteractionResponse(InteractionResult.FAILURE, "Factory has been deactivated!"));
      return response;
    }
  }