Esempio n. 1
0
  /**
   * Think.
   *
   * @param chip
   */
  public void think(ChipState chip) {
    if (triggerOnRising && !chip.getIn(1).is()) {
      return;
    }

    Vector blockPos = chip.getBlockPosition();

    int x = blockPos.getBlockX();
    int y = blockPos.getBlockY();
    int z = blockPos.getBlockZ();

    try {
      String yOffsetLine = chip.getText().getLine3();

      if (yOffsetLine.length() > 0) {
        y += Integer.parseInt(yOffsetLine);
      } else {
        y -= 1;
      }
    } catch (NumberFormatException e) {
      y -= 1;
    }

    y = Math.min(Math.max(0, y), 127);

    int type = chip.getWorld().getId(x, y, z);

    chip.getOut(1).set(type == 8 || type == 9);
  }
Esempio n. 2
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();
  }