示例#1
0
  public String validateEnvironment(ServerInterface i, WorldInterface w, Vector v, SignText t) {

    if (!t.getLine3().isEmpty()) return "line 3 is not empty";

    String code;
    try {
      code = getCode(w, v);
    } catch (PlcException e) {
      return "Code block not found.";
    }

    t.setLine3("HASH:" + Integer.toHexString(code.hashCode()));

    return validateEnviromentEx(i, w, v, t);
  }
示例#2
0
  /**
   * Validates the IC's environment. The position of the sign is given. Return a string in order to
   * state an error message and deny creation, otherwise return null to allow.
   *
   * @param sign
   * @return
   */
  public String validateEnvironment(Vector pos, SignText sign) {
    String yOffsetLine = sign.getLine3();

    try {
      if (yOffsetLine.length() > 0) {
        Integer.parseInt(yOffsetLine);
      }
    } catch (NumberFormatException e) {
      return "The third line must be a number or be blank.";
    }

    return null;
  }
示例#3
0
  public void think(ChipState chip) {

    SignText t = chip.getText();

    String code;
    try {
      code = getCode(chip.getWorld(), chip.getPosition());
    } catch (PlcException e) {
      t.setLine2("§c" + t.getLine2());
      t.setLine3("!ERROR!");
      t.setLine4("code not found");
      return;
    }

    if (!t.getLine3().equals("HASH:" + Integer.toHexString(code.hashCode()))) {
      t.setLine2("§c" + t.getLine2());
      t.setLine3("!ERROR!");
      t.setLine4("code modified");
      return;
    }

    boolean[] output;
    try {
      output = language.tick(chip, code);
    } catch (PlcException e) {
      t.setLine2("§c" + t.getLine2());
      t.setLine3("!ERROR!");
      t.setLine4(e.getMessage());
      return;
    } catch (Throwable r) {
      t.setLine2("§c" + t.getLine2());
      t.setLine3("!ERROR!");
      t.setLine4(r.getClass().getSimpleName());
      return;
    }

    try {
      for (int i = 0; i < output.length; i++) {
        Signal out = chip.getOut(i + 1);
        if (out == null) break;
        out.set(output[i]);
      }
    } catch (ArrayIndexOutOfBoundsException e) {
      t.setLine2("§c" + t.getLine2());
      t.setLine3("!ERROR!");
      t.setLine4("too many outputs");
      return;
    }

    t.supressUpdate();
  }