Ejemplo n.º 1
0
  @Override
  public void trigger(ChipState chip) {

    if (chip.getInput(0)) {
      chip.setOutput(0, hurt());
    }
  }
  @Override
  public void trigger(ChipState chip) {

    if (chip.get(0)) {
      chip.set(3, chip.get(1));
    }

    if (chip.get(2)) {
      chip.set(3, false);
    }
  }
Ejemplo n.º 3
0
  @Override
  public void trigger(ChipState chip) {

    boolean set = chip.get(0);
    boolean reset = chip.get(1);

    if (!set && !reset) {
      chip.set(3, true);
    } else if (set && !reset) {
      chip.set(3, false);
    } else if (!set && reset) {
      chip.set(3, true);
    }
  }
Ejemplo n.º 4
0
  @Override
  public void think(ChipState chip) {

    if (chip.getInput(0)) {
      triggerClock(chip);
    }
  }
Ejemplo n.º 5
0
  @Override
  public void trigger(ChipState chip) {

    int on = 0, valid = 0;
    for (int i = 0; i < chip.getInputCount(); i++) {

      if (chip.isValid(i)) {
        valid++;

        if (chip.getInput(i)) on++;
      }
    }

    // Condition; all valid must be ON, at least one valid.
    chip.setOutput(0, (on == valid && valid > 0));
  }
Ejemplo n.º 6
0
  /**
   * Think.
   *
   * @param chip
   */
  @Override
  public void think(ChipState chip) {

    if (chip.inputAmount() == 0 || (chip.getIn(1).is() && chip.getIn(1).isTriggered())) {
      double dist = 5;
      if (!chip.getText().getLine4().isEmpty())
        dist = Double.parseDouble(chip.getText().getLine4());
      dist *= dist;
      Vector lever = Util.getWallSignBack(chip.getCBWorld(), chip.getPosition(), 2);
      World world = CraftBook.getWorld(chip.getCBWorld());

      NearbyEntityFinder nearbyFinder =
          new NearbyEntityFinder(
              world, chip.getBlockPosition(), lever, dist, chip.getText().getLine3(), 0, false);
      etc.getServer().addToServerQueue(nearbyFinder);
    }
  }
Ejemplo n.º 7
0
  /**
   * Think.
   *
   * @param chip
   */
  @Override
  public void think(ChipState chip) {
    if (!chip.getIn(1).is() || !chip.getIn(1).isTriggered()) return;

    boolean damaged =
        damagePlayers(
            CraftBook.getWorld(chip.getCBWorld()),
            chip.getBlockPosition().getBlockX(),
            chip.getBlockPosition().getBlockY(),
            chip.getBlockPosition().getBlockZ(),
            Integer.parseInt(chip.getText().getLine4()),
            chip.getText().getLine3().toLowerCase());

    chip.getOut(1).set(damaged);
  }
Ejemplo n.º 8
0
  public boolean setMemory(ChipState chip) {
    try {
      File f = new File("plugins/CraftBookCircuits/ROM/", getSign().getLine(2));
      if (!f.exists()) f.createNewFile();
      PrintWriter pw = new PrintWriter(f);
      for (int i = 0; i < 2; i++)
        if (chip.getInput(i)) pw.println("1");
        else pw.println("0");
      pw.close();
    } catch (Exception e) {

    }
    return false;
  }
Ejemplo n.º 9
0
  protected void triggerClock(ChipState chip) {

    short tick, reset;
    try {
      reset = Short.parseShort(getSign().getLine(2));
    } catch (NumberFormatException e) {
      return;
    }

    try {
      tick = Short.parseShort(getSign().getLine(3));
    } catch (NumberFormatException e) {
      tick = 0;
    }

    tick++;

    if (tick == reset) {
      tick = 0;
      chip.setOutput(0, !chip.getOutput(0));
    }

    getSign().setLine(3, Short.toString(tick));
  }
Ejemplo n.º 10
0
  @Override
  public void execute(ChipState chip, boolean[] state, WithLineInfo<String>[] code)
      throws PlcException {

    boolean[] tt = new boolean[32];
    boolean a = chip.getInputCount() > 0 && chip.getInput(0);
    boolean b = chip.getInputCount() > 1 && chip.getInput(1);
    boolean c = chip.getInputCount() > 2 && chip.getInput(2);

    for (int i = 0; i < chip.getOutputCount(); i++)
      if (i < code.length) {
        Boolean r = executeFunction(i, state, tt, code, a, b, c, new boolean[0], new int[1], 0);
        if (r == null) {
          chip.setOutput(i, false);
        } else {
          chip.setOutput(i, r);
        }
      } else {
        chip.setOutput(i, false);
      }
  }
Ejemplo n.º 11
0
 @Override
 public void think(ChipState state) {
   if (state.getInput(0)) {
     for (Player p : getSign().getWorld().getPlayers()) {
       int radius = 10, effectID = 1, effectAmount = 1, effectTime = 10;
       try {
         effectID = Integer.parseInt(getSign().getLine(2).split(":")[0]);
         effectAmount = Integer.parseInt(getSign().getLine(2).split(":")[1]);
         effectTime = Integer.parseInt(getSign().getLine(2).split(":")[2]);
         radius = Integer.parseInt(getSign().getLine(3));
       } catch (Exception e) {
       }
       if (p.getLocation().distance(getSign().getLocation()) > radius) continue;
       p.addPotionEffect(
           new PotionEffect(PotionEffectType.getById(effectID), effectTime * 20, effectAmount - 1),
           true);
     }
   }
 }
Ejemplo n.º 12
0
  @Override
  public void think(ChipState chip) {

    chip.setOutput(0, hurt());
  }
Ejemplo n.º 13
0
  @Override
  public void trigger(ChipState chip) {

    if (chip.getInput(0)) shootFire(5);
  }