Record Class ResearchTrigger

java.lang.Object
java.lang.Record
com.pixelmonmod.pixelmon.api.research.ResearchTrigger
Record Components:
events - The events that should trigger the research
condition - The condition that should be met for the research to start
research - The research that can be started

public record ResearchTrigger(Set<InteractionEvent> events, InteractionCondition condition, RewardPool<ConditionalResearch> research) extends Record
A ResearchTrigger is a datapackable concept that dictates when a player should receive/start a Research.
This is done by passing all interaction events through all the registered triggers to check if the event is relevant to the trigger, and if the condition is met, then the trigger will start the desired number of research for the player.
To create a ResearchTrigger, you need to register it to the PixelmonRegistry.RESEARCH_TRIGGER_REGISTRY but this should be done through a datapack.
  • Field Details

    • CODEC

      public static final com.mojang.serialization.Codec<ResearchTrigger> CODEC
  • Constructor Details

    • ResearchTrigger

      public ResearchTrigger(List<InteractionEvent> events, InteractionCondition condition, RewardPool<ConditionalResearch> research)
      An ease of use constructor for creating a ResearchTrigger that converts the List to a Set
      Parameters:
      events - The events that should trigger the research
      condition - The condition that should be met for the research to start
      research - The research that can be started
    • ResearchTrigger

      public ResearchTrigger(Set<InteractionEvent> events, InteractionCondition condition, RewardPool<ConditionalResearch> research)
      Constructor that creates an immutable copy of the set of events.
      Parameters:
      events - The events that should trigger the research
      condition - The condition that should be met for the research to start
      research - The research that can be started
  • Method Details

    • handleEvent

      public void handleEvent(InteractionEvent event, InteractionContext context)
      The logic to check that the event fired is relevant to this trigger, then to check that the condition is met, and then to start the desired number of research for the player in the context.
      Parameters:
      event - The event that was fired
      context - The context of the event
    • toJson

      public com.google.gson.JsonElement toJson()
      Converts the ResearchTrigger to a JsonElement using the CODEC
      Returns:
      The ResearchTrigger as a JsonElement
    • saveToFile

      public void saveToFile(File file) throws IOException
      Saves the ResearchTrigger to a file using the toJson() method
      Parameters:
      file - The file to save the ResearchTrigger to
      Throws:
      IOException - If an error occurs while saving the file
    • builder

      public static ResearchTrigger.Builder builder()
      Creates a new builder for a ResearchTrigger
      Returns:
      The builder
    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared with Objects::equals(Object,Object).
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • events

      public Set<InteractionEvent> events()
      Returns the value of the events record component.
      Returns:
      the value of the events record component
    • condition

      public InteractionCondition condition()
      Returns the value of the condition record component.
      Returns:
      the value of the condition record component
    • research

      public RewardPool<ConditionalResearch> research()
      Returns the value of the research record component.
      Returns:
      the value of the research record component