Mixson Hooks lay in between Mixson and Minecraft. They provide methods for interacting with a collection of Resource
that Mixson uses to operate events and runtimes. Mixson has three built-in hooks: StandardHook, ListHook, and
NamespaceHook, all of which extend the AbstractHook<T> class.
Each hook deals with a specific collection, hence the generic T in the AbstractHook. The StandardHook deals with
Map<Identifier, Resource>, the ListHook deals with Map<Identifier, List<Resource>>, and the NamespaceHook deals
with List<Resource>. These three hooks cover all aspects of vanilla resource management.
However, it is possible that a modder may need to hook Mixson elsewhere.
AbstractHook
A class extending AbstractHook must be created. the class is defined as follows:
public abstract class AbstractHook<T> {protected final T attachedResources;public AbstractHook(T attachedResources) {this.attachedResources = attachedResources;}public abstract Optional<List<Resource>> captureFiles(Index index, String fileExt);public abstract List<Map.Entry<Index, Resource>> getMatching(Predicate<Index> predicate);public abstract void insert(Index index, List<Resource> resources, String fileExt, boolean overwrite);public abstract void delete(Index index, String fileExt);}
When a hook is run, the collection of Resource is kept in the attachedResources field. That field should be queried
by the abstract method implementations.
The captureFiles method should return an Optional<List<Resource>>. The optional should be empty if the provided
index and extension do not match anything in the hook's collection. If the index does match, even if it matches to
nothing, the optional should contain a list of the resources. This method is called upon EventContext#captureFiles
being called.
The getMatching method should return List<Map.Entry<Index, Resource>>. The method should apply the provided
predicate to every resource in the hook's collection. If the predicate matches, the resource should be added to the
resulting list along with its corresponding index, which must be created by the method.
The insert method should insert the provided resources into the hook's collection. The provided list should never be
empty. The provided index does not include the file extension, so the method will need to apply it. The method is to
throw an error if the index provided already exists in the hook's collection and the overwrite parameter is false.
If there is more than one resource in the list, the overwrite parameter must be set to true.
The delete method should delete the provided Index from the hook's collection. The Index does not include the file
extension, so the method will need to apply it. An invalid Index should not throw an error, unless the Idenfifier
matches, and the ordinal is out of bounds.
Once all of that is done, the hook can be used by passing an instance of it to Mixson#processHook. This method will
trigger a runtime and begin calling Mixson events.
See any of the builtin hooks for an example.