static {
    try {

      isBadEffect = ReflectionHelper.findField(Potion.class, "isBadEffect", "field_76418_K");

    } catch (Throwable t) {

      ModLog.warn("Unable to hook Potion.isBadEffect");

      ;
    }
  }
Ejemplo n.º 2
0
  public static Optional<ItemStack> getItemStack(final String name, final int quantity) {

    if (name == null || name.isEmpty()) return Optional.absent();

    // Check our preferred list first. If we have a hit, use it.
    ItemStack result = PreferredItemStacks.instance.get(name);

    if (result != null) {

      result = result.copy();
      result.stackSize = quantity;

    } else {

      // Parse out the possible subtype from the end of the string
      String workingName = name;
      int subType = -1;

      if (StringUtils.countMatches(name, ":") == 2) {
        workingName = StringUtils.substringBeforeLast(name, ":");
        final String num = StringUtils.substringAfterLast(name, ":");

        if (num != null && !num.isEmpty()) {

          if ("*".compareTo(num) == 0) subType = OreDictionaryHelper.WILDCARD_VALUE;
          else {
            try {
              subType = Integer.parseInt(num);
            } catch (Exception e) {
              // It appears malformed - assume the incoming name
              // is
              // the real name and continue.
              ;
            }
          }
        }
      }

      // Check the OreDictionary first for any alias matches. Otherwise
      // go to the game registry to find a match.
      final List<ItemStack> ores = OreDictionaryHelper.getOres(workingName);
      if (!ores.isEmpty()) {
        result = ores.get(0).copy();
        result.stackSize = quantity;
      } else {
        final Item i = GameData.getItemRegistry().getObject(workingName);
        if (i != null) {
          result = new ItemStack(i, quantity);
        }
      }

      // If we did have a hit on a base item, set the sub-type
      // as needed.
      if (result != null && subType != -1) {
        if (subType == OreDictionaryHelper.WILDCARD_VALUE && !result.getHasSubtypes()) {
          ModLog.warn("[%s] GENERIC requested but Item does not support sub-types", name);
        } else {
          result.setItemDamage(subType);
        }
      }
    }

    return Optional.fromNullable(result);
  }