Class StoredContext

java.lang.Object
com.pixelmonmod.pixelmon.api.context.StoredContext
Direct Known Subclasses:
StrictStoredContext

public sealed class StoredContext extends Object permits StrictStoredContext
An object for storing generic data in a map without the burden of having to cast, or deal with the generic types.
Additionally, each ContextKey has placeholder logic for replacing data in a string with the data stored in the context
All data stored in this context must be immutable.
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
     
  • Method Summary

    Modifier and Type
    Method
    Description
     
    <A> Optional<A>
    Gets the value stored by a given context key for this stored context
    <A> Optional<A>
    getContext(net.minecraft.resources.ResourceLocation key)
    Gets the value stored by a given context key for this stored context
    getContextType(net.minecraft.resources.ResourceLocation key)
    Gets the type of the context stored by the given key
    This will return null if the key is not found in the context
    <A> A
    Gets the value stored by a given context key for this stored context
    <A> A
    getNullableContext(net.minecraft.resources.ResourceLocation key)
    Gets the value stored by a given context key for this stored context
    boolean
    Checks if the context has the given key
    boolean
    hasContext(net.minecraft.resources.ResourceLocation key)
    Checks if the context has the given key
    of()
    Gets an instance of a new Stored context
    static <A> StoredContext
    of(ContextKey<A> key, A value)
    Gets an instance of a new StoredContext with the key and value set already
    replace(String originalText)
    Handles the replacement of the placeholders in the text
    net.minecraft.network.chat.Component
    replace(net.minecraft.network.chat.Component originalText)
     
    setContext(ContextKey<A> key, A value)
    Sets the context key with the given value
    setContext(net.minecraft.resources.ResourceLocation key, A value)
    Sets the context key with the given value
    Gets an instance of a new Stored context
    static <A> StoredContext
    strict(ContextKey<A> key, A value)
    Gets an instance of a new StoredContext with the key and value set already
    withPlayer(net.minecraft.server.level.ServerPlayer player)
    Adds the generic contexts for the player

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • StoredContext

      protected StoredContext()
  • Method Details

    • of

      public static StoredContext of()
      Gets an instance of a new Stored context
      Returns:
      new stored context
    • strict

      public static StoredContext strict()
      Gets an instance of a new Stored context
      Returns:
      new stored context
    • of

      public static <A> StoredContext of(ContextKey<A> key, A value)
      Gets an instance of a new StoredContext with the key and value set already
      Type Parameters:
      A - The type of the key and value
      Parameters:
      key - The key
      value - The value being set
      Returns:
      new StoredContext context
    • strict

      public static <A> StoredContext strict(ContextKey<A> key, A value)
      Gets an instance of a new StoredContext with the key and value set already
      Type Parameters:
      A - The type of the key and value
      Parameters:
      key - The key
      value - The value being set
      Returns:
      new StoredContext context
    • setContext

      public <A> StoredContext setContext(ContextKey<A> key, @Nullable A value)
      Sets the context key with the given value
      Type Parameters:
      A - The type of the key and value
      Parameters:
      key - The key
      value - The value being set
      Returns:
      The context instance
    • setContext

      public <A> StoredContext setContext(net.minecraft.resources.ResourceLocation key, @Nullable A value)
      Sets the context key with the given value
      Type Parameters:
      A - The type of the key and value
      Parameters:
      key - The key
      value - The value being set
      Returns:
      The context instance
    • withPlayer

      public StoredContext withPlayer(net.minecraft.server.level.ServerPlayer player)
      Adds the generic contexts for the player
      Parameters:
      player - The player for adding the generic contexts
      Returns:
      The context instance
    • getContext

      public <A> Optional<A> getContext(ContextKey<A> key)
      Gets the value stored by a given context key for this stored context
      Type Parameters:
      A - The type of the key and value
      Parameters:
      key - The key to check for
      Returns:
      The potential value stored
    • getNullableContext

      @Nullable public <A> A getNullableContext(ContextKey<A> key)
      Gets the value stored by a given context key for this stored context
      Type Parameters:
      A - The type of the key and value
      Parameters:
      key - The key to check for
      Returns:
      The potential value stored
    • getContext

      public <A> Optional<A> getContext(net.minecraft.resources.ResourceLocation key)
      Gets the value stored by a given context key for this stored context
      Type Parameters:
      A - The type of the key and value
      Parameters:
      key - The key to check for
      Returns:
      The potential value stored
    • getNullableContext

      @Nullable public <A> A getNullableContext(net.minecraft.resources.ResourceLocation key)
      Gets the value stored by a given context key for this stored context
      Type Parameters:
      A - The type of the key and value
      Parameters:
      key - The key to check for
      Returns:
      The potential value stored
    • hasContext

      public boolean hasContext(net.minecraft.resources.ResourceLocation key)
      Checks if the context has the given key
      Parameters:
      key - The key to check for
      Returns:
      If the context has the key
    • hasContext

      public boolean hasContext(ContextKey<?> key)
      Checks if the context has the given key
      Parameters:
      key - The key to check for
      Returns:
      If the context has the key
    • getContextType

      @Nullable public Class<?> getContextType(net.minecraft.resources.ResourceLocation key)
      Gets the type of the context stored by the given key
      This will return null if the key is not found in the context
      Parameters:
      key - The key to check for
      Returns:
      The type of the context key
    • replace

      public String replace(String originalText)
      Handles the replacement of the placeholders in the text
      Parameters:
      originalText - The text to replace
      Returns:
      The text with the placeholders replaced
    • replace

      public net.minecraft.network.chat.Component replace(net.minecraft.network.chat.Component originalText)
    • copy

      public StoredContext copy()