Ejemplo n.º 1
0
  public ItemList<NamedItemStack> getInputs() {
    ItemList<NamedItemStack> inputs = new ItemList<NamedItemStack>();
    Inventory inv = getInventory();
    if (mode.equals(CompactorMode.DECOMPACT)) {
      for (ItemStack is : inv.getContents()) {
        if (canDecompact(is)) {
          NamedItemStack clone =
              new NamedItemStack(
                  is.clone(),
                  is.getItemMeta().hasDisplayName()
                      ? is.getItemMeta().getDisplayName()
                      : is.getType().toString());
          clone.setAmount(1);
          inputs.add(clone);

          return inputs;
        }
      }
    } else if (mode.equals(CompactorMode.COMPACT)) {
      for (ItemStack is : inv.getContents()) {
        if (canCompact(is)) {
          NamedItemStack clone =
              new NamedItemStack(
                  is.clone(),
                  is.getItemMeta().hasDisplayName()
                      ? is.getItemMeta().getDisplayName()
                      : is.getType().toString());
          inputs.add(clone);

          inputs.addAll(cp.getRecipeMaterials());
          return inputs;
        }
      }
    }
    return inputs;
  }
Ejemplo n.º 2
0
 public ItemList<NamedItemStack> getAllInputs() {
   ItemList<NamedItemStack> allInputs = new ItemList<NamedItemStack>();
   allInputs.addAll(getInputs());
   allInputs.addAll(getRepairs());
   return allInputs;
 }
Ejemplo n.º 3
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;
    }
  }
Ejemplo n.º 4
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;
    }
  }