Warning
This page only gives the minimum details for using V2 Mixson. All information on this page IS outdated. Revisit the entire wiki to be update-to-date on all features available.
Lifetimes
Events now have a Lifetime parameter. The lifetime determines at what point the event should no longer be processed.
All normal events from V1 fall under the lifetime Lifetime.PERSISTANT. Runtime events fall under the lifetime
Lifetime.DEFERRED. Instead of calling EventContext#registerRuntimeEvent, the method EventContext#pullInRuntimeEvent
should be used instead. This new method takes in the UUID of the registered event, which is returned by the
registration method.
Error Policies
Events now have an ErrorPolicy parameter. The error policy determines what should happen if an error occurs during
the event. Events from V1 with "fail silently" set to true fall under the error policy ErrorPolicy.LOG.
Events from V1 with "fail silently" set to false fall under the error policy ErrorPolicy.THROW.
Index
Events and References no longer go off of Identifiers and ints seperately. Instead, they are combined into an
Index class. The index takes in the Identifier and the int ordinal. If the ordinal is not specified, it is assumed
to be -1. Index can be constructed through one of the four constructors:
public Index(Identifier id, int ordinal);public Index(String stringId, int ordinal);public Index(Identifier id);public Index(String stringId);
Resource References
Resource References are no longer associated with a specific event. They also no longer update the resource file but rather create a copy of it. Resource References are automatically updating copies of the resource file. The reference itself is no longer restricted to only being usable during an event, but rather can be used anywhere.
There are now two methods for registering ResourceReferences:
public static ResourceReference<JsonElement> registerReference(int priority, Index index, String referenceName);public static <T> ResourceReference<T> registerReference(MixsonCodec<T> codec, int priority, Index index, String referenceName);
References inside events have been replaced with capturing. The EventContext#captureFiles method can be called by
passing an Index to get a list of mutable resources.
Old Example
Mixson.registerEvent(...context -> {BuiltResourceReference<T> ref = context.getReference("referenceName");JsonElement element = ref.retrieve().orElseThrow();/* stuff */},...new ResourceReference(Mixson.DEFAULT_PRIORITY, "minecraft:resource/location", "referenceName"));
Updated Example
Mixson.registerEvent(...context -> {List<Mutable<JsonElement>> captures = context.captureFiles(new Index("minecraft:resource/location"));JsonElement element = captures.getFirst().get();});
Registering Events
There are now three methods to use for event registration that can both be found in the Mixson class:
public static UUID registerEvent(int priority, Lifetime lifetime, ErrorPolicy errorPolicy, String eventName, Predicate<Index> resourcePredicate, Event<JsonElement> event);public static <T> UUID registerEvent(MixsonCodec<T> codec, int priority, Lifetime lifetime, ErrorPolicy errorPolicy, String eventName, Predicate<Index> resourcePredicate, Event<T> event);public static <T> UUID registerEvent(MixsonEventBuilder<T> builder);
The MixsonEvent interface was renamed to Event. The Event interface no longer has an ordinal method. Instead,
pass the ordinal to the Index.
The ResourceLocator interface was removed and replaced with Predicate<Index>, which does the same thing.
the resourceId is now converted to an Identifier (or ResourceLocation) during registration, so only a string needs
to be passed.
the eventId has been replaced with eventName which replaces the BaseEvent#getName used for debugging. The
eventName is not converted to an Identifier, so there are no restrictions on what it can be.
Old Example
Mixson.registerEvent(Mixson.JSON_ELEMENT_CODEC,Mixson.DEFAULT_PRIORITY,identifier -> identifier.equals(/*id*/),"EventName",context -> {/* do stuff */},false);
Updated Example
Mixson.registerEvent(MixsonCodecs.JSON_ELEMENT,Mixson.DEFAULT_PRIORITY,Lifetime.PERSISTENT,ErrorPolicy.THROW,"EventName",index -> index.idEquals(/*id*/),context -> {/* do stuff */});
The Mixson Command as well as Mixson APT were removed.