Class StandardFactoryController

java.lang.Object
com.minecolonies.api.colony.requestsystem.StandardFactoryController
All Implemented Interfaces:
IFactoryController

public final class StandardFactoryController extends Object implements IFactoryController
Default implementation of a FactoryController Singleton.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final String
     
    static final String
     
    static final String
     
  • Method Summary

    Modifier and Type
    Method
    Description
    <OUTPUT> OUTPUT
    deserialize(@NotNull net.minecraft.nbt.CompoundTag compound)
    Method used to quickly deserialize a object if it is known to this controller.
    <OUTPUT> OUTPUT
    deserialize(@NotNull net.minecraft.network.FriendlyByteBuf buffer)
    Method used to quickly read an object from a given ByteBuf
    <INPUT> IFactory<INPUT,?>
    getFactoryForInput(@NotNull com.google.common.reflect.TypeToken<? extends INPUT> inputClass)
    Method used to get a factory for a given input class.
    <INPUT, OUTPUT>
    IFactory<INPUT,OUTPUT>
    getFactoryForIO(@NotNull com.google.common.reflect.TypeToken<? extends INPUT> inputClass, @NotNull com.google.common.reflect.TypeToken<? extends OUTPUT> outputClass)
    Method to get a factory for a given combination of input and output types.
    <OUTPUT> IFactory<?,OUTPUT>
    getFactoryForOutput(@NotNull com.google.common.reflect.TypeToken<? extends OUTPUT> outputClass)
    Method used to get a factory for a given output class.
    <OUTPUT> IFactory<?,OUTPUT>
    Method used to get a factory for a given output class.
    Method to get the current instance of the StandardFactoryController
    <OUTPUT> OUTPUT
    getNewInstance(@NotNull com.google.common.reflect.TypeToken<? extends OUTPUT> requestedType)
    Method used to create a new instance of the given output.
    <INPUT, OUTPUT>
    OUTPUT
    getNewInstance(@NotNull com.google.common.reflect.TypeToken<? extends OUTPUT> requestedType, INPUT input, @NotNull Object... context)
    Method used to create a new instance of the given input.
    <INPUT, OUTPUT>
    void
    registerNewFactory(@NotNull IFactory<INPUT,OUTPUT> factory)
    Method used to register a new factory to this controller.
    <OUTPUT> void
    registerNewTypeOverrideHandler(@NotNull ITypeOverrideHandler<OUTPUT> overrideHandler)
    Method used to register a TypeOverride handler.
    static void
    Resets the FactoryController to the default values.
    <OUTPUT> void
    serialize(@NotNull net.minecraft.network.FriendlyByteBuf buffer, OUTPUT object)
    Method used to quickly write an object into the given ByteBuf.
    <OUTPUT> net.minecraft.nbt.CompoundTag
    serialize(OUTPUT object)
    Method used to quickly serialize a object if it is known to this controller.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface com.minecolonies.api.colony.requestsystem.factory.IFactoryController

    deserializeList, getFactoryForInput, getFactoryForOutput, getFactoryForOutput, serializeList
  • Field Details

  • Method Details

    • reset

      public static void reset()
      Resets the FactoryController to the default values. Clears all registered Factories.

      Only used for testing.

    • getInstance

      public static StandardFactoryController getInstance()
      Method to get the current instance of the StandardFactoryController
      Returns:
      The current instance of the standard factory controller.
    • getFactoryForIO

      public <INPUT, OUTPUT> IFactory<INPUT,OUTPUT> getFactoryForIO(@NotNull @NotNull com.google.common.reflect.TypeToken<? extends INPUT> inputClass, @NotNull @NotNull com.google.common.reflect.TypeToken<? extends OUTPUT> outputClass) throws IllegalArgumentException
      Description copied from interface: IFactoryController
      Method to get a factory for a given combination of input and output types.
      Specified by:
      getFactoryForIO in interface IFactoryController
      Type Parameters:
      INPUT - The input type of the factory
      OUTPUT - The output type of the factory.
      Parameters:
      inputClass - The input type of the factory.
      outputClass - The output type of the factory.
      Returns:
      A factory that takes the input type and produces the output type.
      Throws:
      IllegalArgumentException - Thrown when no factory exists for the combination of input and output.
    • getFactoryForInput

      public <INPUT> IFactory<INPUT,?> getFactoryForInput(@NotNull @NotNull com.google.common.reflect.TypeToken<? extends INPUT> inputClass) throws IllegalArgumentException
      Description copied from interface: IFactoryController
      Method used to get a factory for a given input class.
      Specified by:
      getFactoryForInput in interface IFactoryController
      Type Parameters:
      INPUT - The type of input for the requested factory.
      Parameters:
      inputClass - The class of the input type of the requested factory.
      Returns:
      The factory that can handle the given input class.
      Throws:
      IllegalArgumentException - is thrown when the given input class is unknown to this Factory Controller.
    • getFactoryForOutput

      public <OUTPUT> IFactory<?,OUTPUT> getFactoryForOutput(@NotNull @NotNull com.google.common.reflect.TypeToken<? extends OUTPUT> outputClass) throws IllegalArgumentException
      Description copied from interface: IFactoryController
      Method used to get a factory for a given output class.
      Specified by:
      getFactoryForOutput in interface IFactoryController
      Type Parameters:
      OUTPUT - The type of output for the requested factory.
      Parameters:
      outputClass - The class of the output type of the requested factory.
      Returns:
      The factory that can handle the given output class.
      Throws:
      IllegalArgumentException - is thrown when the given output class is unknown to this Factory Controller.
    • getFactoryForSerializationId

      public <OUTPUT> IFactory<?,OUTPUT> getFactoryForSerializationId(short id) throws IllegalArgumentException
      Description copied from interface: IFactoryController
      Method used to get a factory for a given output class.
      Specified by:
      getFactoryForSerializationId in interface IFactoryController
      Type Parameters:
      OUTPUT - The type of output for the requested factory.
      Parameters:
      id - The id of the output type of the requested factory.
      Returns:
      The factory that can handle the given output class.
      Throws:
      IllegalArgumentException - is thrown when the given output class is unknown to this Factory Controller.
    • registerNewFactory

      public <INPUT, OUTPUT> void registerNewFactory(@NotNull @NotNull IFactory<INPUT,OUTPUT> factory) throws IllegalArgumentException
      Description copied from interface: IFactoryController
      Method used to register a new factory to this controller.
      Specified by:
      registerNewFactory in interface IFactoryController
      Type Parameters:
      INPUT - The type of input the factory accepts.
      OUTPUT - The type of output the factory produces.
      Parameters:
      factory - The new factory.
      Throws:
      IllegalArgumentException - if there is already a factory registered with either the given input and/or the given output.
    • serialize

      public <OUTPUT> net.minecraft.nbt.CompoundTag serialize(@NotNull OUTPUT object) throws IllegalArgumentException
      Description copied from interface: IFactoryController
      Method used to quickly serialize a object if it is known to this controller.
      Specified by:
      serialize in interface IFactoryController
      Type Parameters:
      OUTPUT - the output type.
      Parameters:
      object - The object to serialize.
      Returns:
      An NBTTag containing a serialized version of the given object.
      Throws:
      IllegalArgumentException - is thrown when the output type is unknown to this controller.
    • deserialize

      public <OUTPUT> OUTPUT deserialize(@NotNull @NotNull net.minecraft.nbt.CompoundTag compound) throws IllegalArgumentException
      Description copied from interface: IFactoryController
      Method used to quickly deserialize a object if it is known to this controller.
      Specified by:
      deserialize in interface IFactoryController
      Type Parameters:
      OUTPUT - The type of object to deserialize.
      Parameters:
      compound - The data to deserialize an object from.
      Returns:
      The deserialized version of the given data.
      Throws:
      IllegalArgumentException - is thrown when the type stored in the data is unknown to this controller.
    • serialize

      public <OUTPUT> void serialize(@NotNull @NotNull net.minecraft.network.FriendlyByteBuf buffer, @NotNull OUTPUT object) throws IllegalArgumentException
      Description copied from interface: IFactoryController
      Method used to quickly write an object into the given ByteBuf.
      Specified by:
      serialize in interface IFactoryController
      Type Parameters:
      OUTPUT - The type of the object to write.
      Parameters:
      buffer - The buffer to write into.
      object - The object to write.
      Throws:
      IllegalArgumentException - is thrown when the given output type is unknown to this controller.
    • deserialize

      public <OUTPUT> OUTPUT deserialize(@NotNull @NotNull net.minecraft.network.FriendlyByteBuf buffer) throws IllegalArgumentException
      Description copied from interface: IFactoryController
      Method used to quickly read an object from a given ByteBuf
      Specified by:
      deserialize in interface IFactoryController
      Type Parameters:
      OUTPUT - The type to read.
      Parameters:
      buffer - The buffer to read from.
      Returns:
      An instance of the given output type, with its stored data from the buffer.
      Throws:
      IllegalArgumentException - is thrown when the requested type is unknown to this controller.
    • getNewInstance

      public <INPUT, OUTPUT> OUTPUT getNewInstance(@NotNull @NotNull com.google.common.reflect.TypeToken<? extends OUTPUT> requestedType, @NotNull INPUT input, @NotNull @NotNull Object... context) throws IllegalArgumentException, ClassCastException
      Description copied from interface: IFactoryController
      Method used to create a new instance of the given input.
      Specified by:
      getNewInstance in interface IFactoryController
      Type Parameters:
      INPUT - The type of input.
      OUTPUT - The type of output.
      Parameters:
      requestedType - The typetoken for the requested type.
      input - The input to process.
      context - The context for the creation.
      Returns:
      The output from the factory, created by the given input and output.
      Throws:
      IllegalArgumentException - thrown when the output and input do not match a factory known to this controller.
      ClassCastException - thrown when a Factory is known for the given input, but does not produce the given output.
    • getNewInstance

      public <OUTPUT> OUTPUT getNewInstance(@NotNull @NotNull com.google.common.reflect.TypeToken<? extends OUTPUT> requestedType) throws IllegalArgumentException
      Description copied from interface: IFactoryController
      Method used to create a new instance of the given output.
      Specified by:
      getNewInstance in interface IFactoryController
      Type Parameters:
      OUTPUT - The type of output.
      Parameters:
      requestedType - The typetoken of the requested type.
      Returns:
      The output from the factory, created by the given input and output.
      Throws:
      IllegalArgumentException - thrown when the output and input do not match a factory known to this controller.
    • registerNewTypeOverrideHandler

      public <OUTPUT> void registerNewTypeOverrideHandler(@NotNull @NotNull ITypeOverrideHandler<OUTPUT> overrideHandler)
      Description copied from interface: IFactoryController
      Method used to register a TypeOverride handler. Useful if the Client side has a different Handler. Or if an upgrade between version is needed.
      Specified by:
      registerNewTypeOverrideHandler in interface IFactoryController
      Type Parameters:
      OUTPUT - The output type that the handler converts to.
      Parameters:
      overrideHandler - The override handler to register.