Ejemplo n.º 1
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();
  }