Class StandardFactoryController
java.lang.Object
com.minecolonies.api.colony.requestsystem.StandardFactoryController
- All Implemented Interfaces:
IFactoryController
Default implementation of a FactoryController Singleton.
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescription<OUTPUT> OUTPUTdeserialize(@NotNull net.minecraft.nbt.CompoundTag compound) Method used to quickly deserialize a object if it is known to this controller.<OUTPUT> OUTPUTdeserialize(@NotNull net.minecraft.network.FriendlyByteBuf buffer) Method used to quickly read an object from a givenByteBuf<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> getFactoryForSerializationId(short id) Method used to get a factory for a given output class.static StandardFactoryControllerMethod to get the current instance of the StandardFactoryController<OUTPUT> OUTPUTgetNewInstance(@NotNull com.google.common.reflect.TypeToken<? extends OUTPUT> requestedType) Method used to create a new instance of the given output.<INPUT,OUTPUT>
OUTPUTgetNewInstance(@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>
voidregisterNewFactory(@NotNull IFactory<INPUT, OUTPUT> factory) Method used to register a new factory to this controller.<OUTPUT> voidregisterNewTypeOverrideHandler(@NotNull ITypeOverrideHandler<OUTPUT> overrideHandler) Method used to register a TypeOverride handler.static voidreset()Resets the FactoryController to the default values.<OUTPUT> voidserialize(@NotNull net.minecraft.network.FriendlyByteBuf buffer, OUTPUT object) Method used to quickly write an object into the givenByteBuf.<OUTPUT> net.minecraft.nbt.CompoundTagserialize(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, waitMethods inherited from interface com.minecolonies.api.colony.requestsystem.factory.IFactoryController
deserializeList, getFactoryForInput, getFactoryForOutput, getFactoryForOutput, serializeList
-
Field Details
-
NBT_TYPE
- See Also:
-
NBT_DATA
- See Also:
-
NEW_NBT_TYPE
- See Also:
-
-
Method Details
-
reset
public static void reset()Resets the FactoryController to the default values. Clears all registered Factories.Only used for testing.
-
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:IFactoryControllerMethod to get a factory for a given combination of input and output types.- Specified by:
getFactoryForIOin interfaceIFactoryController- Type Parameters:
INPUT- The input type of the factoryOUTPUT- 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:IFactoryControllerMethod used to get a factory for a given input class.- Specified by:
getFactoryForInputin interfaceIFactoryController- 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:IFactoryControllerMethod used to get a factory for a given output class.- Specified by:
getFactoryForOutputin interfaceIFactoryController- 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:IFactoryControllerMethod used to get a factory for a given output class.- Specified by:
getFactoryForSerializationIdin interfaceIFactoryController- 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 IllegalArgumentExceptionDescription copied from interface:IFactoryControllerMethod used to register a new factory to this controller.- Specified by:
registerNewFactoryin interfaceIFactoryController- 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:IFactoryControllerMethod used to quickly serialize a object if it is known to this controller.- Specified by:
serializein interfaceIFactoryController- 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:IFactoryControllerMethod used to quickly deserialize a object if it is known to this controller.- Specified by:
deserializein interfaceIFactoryController- 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:IFactoryControllerMethod used to quickly write an object into the givenByteBuf.- Specified by:
serializein interfaceIFactoryController- 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:IFactoryControllerMethod used to quickly read an object from a givenByteBuf- Specified by:
deserializein interfaceIFactoryController- 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:IFactoryControllerMethod used to create a new instance of the given input.- Specified by:
getNewInstancein interfaceIFactoryController- 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:IFactoryControllerMethod used to create a new instance of the given output.- Specified by:
getNewInstancein interfaceIFactoryController- 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:IFactoryControllerMethod 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:
registerNewTypeOverrideHandlerin interfaceIFactoryController- Type Parameters:
OUTPUT- The output type that the handler converts to.- Parameters:
overrideHandler- The override handler to register.
-