@Override
  public void load() {

    if (getLine(3).isEmpty()) offset = getBackBlock().getRelative(0, 1, 0).getLocation();
    else offset = ICUtil.parseBlockLocation(getSign(), 3).getLocation();
    item = ItemUtil.getItem(getLine(2));
  }
  @Override
  public void load() {

    radius = ICUtil.parseRadius(getSign());
    String radiusString = radius.getBlockX() + "," + radius.getBlockY() + "," + radius.getBlockZ();
    if (radius.getBlockX() == radius.getBlockY() && radius.getBlockY() == radius.getBlockZ())
      radiusString = String.valueOf(radius.getBlockX());
    if (getLine(2).contains("=")) {
      getSign().setLine(2, radiusString + "=" + RegexUtil.EQUALS_PATTERN.split(getLine(2))[1]);
      centre = ICUtil.parseBlockLocation(getSign(), 2).getLocation();
    } else {
      getSign().setLine(2, radiusString);
      centre = getBackBlock().getLocation();
    }

    include = !getLine(3).startsWith("-");

    for (String bit : getLine(3).replace("-", "").split(",")) {

      filters.add(ItemUtil.getItem(bit));
    }

    chest = getBackBlock().getRelative(0, 1, 0);
  }
  @Override
  public void trigger(ChipState chip) {

    if (!location.getChunk().isLoaded()) return;

    if (!chip.getInput(0)) return;
    Block left = SignUtil.getLeftBlock(BukkitUtil.toSign(getSign()).getBlock());
    ChangedSign effectSign = null;
    if (left.getTypeId() == BlockID.WALL_SIGN) {
      effectSign = BukkitUtil.toChangedSign(left);
    }

    Block right = SignUtil.getRightBlock(BukkitUtil.toSign(getSign()).getBlock());
    ChangedSign armourSign = null;
    if (right.getTypeId() == BlockID.WALL_SIGN) {
      armourSign = BukkitUtil.toChangedSign(right);
    }

    for (int i = 0; i < amount; i++) {
      Entity ent = BukkitUtil.toSign(getSign()).getWorld().spawn(location, type.getEntityClass());

      if (armourSign != null) { // Apply armor
        if (ent instanceof LivingEntity) {

          for (int s = 0; s < 4; s++) {
            String bit = armourSign.getLine(s);

            ItemStack slot = ItemUtil.makeItemValid(ItemUtil.getItem(bit));

            if (s == 0) ((LivingEntity) ent).getEquipment().setHelmet(slot);
            if (s == 1) ((LivingEntity) ent).getEquipment().setChestplate(slot);
            if (s == 2) ((LivingEntity) ent).getEquipment().setLeggings(slot);
            if (s == 3) ((LivingEntity) ent).getEquipment().setBoots(slot);
          }
        }
      }

      Boolean upwards = null;

      while (effectSign != null) { // Apply effects
        for (int s = 0; s < 4; s++) {
          String bit = effectSign.getLine(s);
          if (bit == null || bit.trim().isEmpty()) continue;

          String[] data = RegexUtil.COLON_PATTERN.split(bit);

          if (data[0].equalsIgnoreCase("e")) CreatureSpawner.setEntityData(ent, bit.substring(2));
          else if (data[0].equalsIgnoreCase("r")) {
            EntityType rider = EntityType.fromName(data[1].trim());
            Entity rid = BukkitUtil.toSign(getSign()).getWorld().spawnEntity(location, rider);
            ent.setPassenger(rid);
          } else if (data[0].equalsIgnoreCase("p") && ent instanceof LivingEntity) {
            for (int a = 1; a < data.length; a++) {
              try {
                String[] potionBits = RegexUtil.SEMICOLON_PATTERN.split(data[a]);
                PotionEffect effect =
                    new PotionEffect(
                        PotionEffectType.getById(Integer.parseInt(potionBits[0])),
                        Integer.parseInt(potionBits[1]),
                        Integer.parseInt(potionBits[2]));
                ((LivingEntity) ent).addPotionEffect(effect, true);
              } catch (Exception e) {
              }
            }
          } else if (data[0].equalsIgnoreCase("v")) {
            try {
              double x, y, z;
              String[] coords = RegexUtil.COMMA_PATTERN.split(data[1]);
              x = Double.parseDouble(coords[0]);
              y = Double.parseDouble(coords[1]);
              z = Double.parseDouble(coords[2]);
              ent.setVelocity(new org.bukkit.util.Vector(x, y, z));
            } catch (Exception ignored) {
            }
          } else if (data[0].equalsIgnoreCase("s")) {
            if (!(ent instanceof LivingEntity)) continue;

            ItemStack slot = ItemUtil.makeItemValid(ItemUtil.getItem(bit.replace("s:", "")));
            ((LivingEntity) ent).getEquipment().setItemInHand(slot);
          }
        }
        if (upwards == null) {
          if (BukkitUtil.toSign(effectSign).getBlock().getRelative(0, 1, 0).getTypeId()
              == BlockID.WALL_SIGN) {
            effectSign =
                BukkitUtil.toChangedSign(
                    BukkitUtil.toSign(effectSign).getBlock().getRelative(0, 1, 0));
            upwards = true;
          } else if (BukkitUtil.toSign(effectSign).getBlock().getRelative(0, -1, 0).getTypeId()
              == BlockID.WALL_SIGN) {
            effectSign =
                BukkitUtil.toChangedSign(
                    BukkitUtil.toSign(effectSign).getBlock().getRelative(0, -1, 0));
            upwards = false;
          } else break;
        } else {
          if (BukkitUtil.toSign(effectSign)
                  .getBlock()
                  .getRelative(0, upwards ? 1 : -1, 0)
                  .getTypeId()
              == BlockID.WALL_SIGN)
            effectSign =
                BukkitUtil.toChangedSign(
                    BukkitUtil.toSign(effectSign).getBlock().getRelative(0, upwards ? 1 : -1, 0));
          else break;
        }
      }
    }
  }