Annotation Interface Share


@Target(PARAMETER) @Retention(CLASS) public @interface Share
Allows you to share values between handler methods in the same target method. This is generally preferable to storing the value in a field because this is thread-safe and does not consume any long-term memory.

You must provide an ID for the shared value and the annotated parameter's type must be one of the LocalRef family. The parameter's name is irrelevant and only the ID in the annotation is used to share matching values.

The same reference objects will be passed to all handler methods requesting a given ID within a given target method invocation. By default, IDs are per-mixin, so you don't need to worry about including your modid or anything similar in them. If you specifically want to share values across mixins, set the namespace().

Note: If a @Shared value is read from before it has been written to, no exception is thrown and it will simply return the default value for that type (0, 0f, null, etc), much like a field.

See the wiki article for more info.

  • Required Element Summary

    Required Elements
    Modifier and Type
    Required Element
    Description
    The id for this shared value.
  • Optional Element Summary

    Optional Elements
    Modifier and Type
    Optional Element
    Description
    The namespace for this shared value.
  • Element Details

    • value

      String value
      The id for this shared value.
    • namespace

      String namespace
      The namespace for this shared value. By default, this is the fully-qualified name of the enclosing mixin class to ensure uniqueness. If you want to share values between mixin classes, you can set this to something else, e.g. your mod ID.
      Default:
      ""