code: public static <T, U extends T> T toTagValue(Tag<?> t, Class<? extends T> clazz, U defaultValue) {
          Object o = toTagValue(t);
          if (o == null) {
              return defaultValue;
          }
          try {
              T value = clazz.cast(o);
              return value;
          } catch (ClassCastException e) {
              return defaultValue;
          }
      }
docs: Takes in an NBT tag, sanely checks null status, and then returns it value. This method will return null if the value cannot be cast to the default value.
  
  @param t Tag to get the value from
  @param defaultValue the value to return if the tag or its value is null or the value cannot be cast
  @return the value as an onbject of the same type as the default value, or the default value