예제 #1
0
  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
  public ItemList<NamedItemStack> getOutputs() {
    ItemList<NamedItemStack> outputs = 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(clone.getMaxStackSize());
          ItemMeta cloneMeta = clone.getItemMeta();
          cloneMeta.setLore(null);
          clone.setItemMeta(cloneMeta);
          outputs.add(clone);

          return outputs;
        }
      }
    } 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());
          clone.setAmount(1);
          ItemMeta cloneMeta = clone.getItemMeta();
          List<String> lore = new ArrayList<String>();
          lore.add(cp.getCompactLore());
          cloneMeta.setLore(lore);
          clone.setItemMeta(cloneMeta);

          outputs.add(clone);
          return outputs;
        }
      }
    }
    return outputs;
  }
예제 #3
0
 /**
  * Returns true if the item stack is not null, and has lore where the lore contains the special
  * lore of this factory, and where the item has simple metadata (see canCompact).
  *
  * @param is the ItemStack to check validity of decompaction
  * @return true if can be decompacted, false otherwise
  */
 private boolean canDecompact(ItemStack is) {
   return is != null
       && is.getItemMeta().hasLore()
       && is.getItemMeta().getLore().contains(cp.getCompactLore())
       && is.getItemMeta().getClass().getSuperclass().equals(java.lang.Object.class);
 }