mixson

Updating from V:0.x.x to V:1.0.0

Registering Events

There are now only two methods to use for default registration which can both be found in the Mixson class:

UUID registerEvent(int priority, String resourceId, String eventName, MixsonEvent event, ResourceReference... references);
UUID registerEvent(int priority, String resourceId, String eventName, MixsonEvent event, boolean silentlyFail, ResourceReference... references);

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.registerModificationEvent(
Mixson.DEFAULT_PRIORITY,
Identifier.ofVanilla("models/item/netherite_chestplate"),
Identifier.of(MOD_ID, "testevent"),
(elem) -> {
// do stuff
},
false
);

Updated Example

Mixson.registerEvent(
Mixson.DEFAULT_PRIORITY,
"models/item/netherite_chestplate",
"modid:testevent",
(context) -> {
// do stuff
},
false
);

Events

There is now only one event type: MixsonEvent. Advanced variants have also been removed and reimplemented into this singular event.

The interface is defined as follows:

public interface MixsonEvent {
void runEvent(EventContext context);
default int ordinal() {
return -1;
}
}

the EventContext object provides all the features (and more) that the previous events could do

Modification Events

To modify the resource, call EventContext#getFile to receive a modifiable JsonElement.

Old Example

(elem) -> {
// modify elem here
}

New Example

(context) -> {
JsonElement elem = context.getFile();
// modify elem here
}

Creation Events

To create a resource, call one of the EventContext#createResource methods. The methods are defined as follows:

void createResource(ResourceLocation id, JsonElement elem); // use on Identified Resources
void createResource(JsonElement elem); // use on Indexed Resources

An event will only ever use one of these depending on whether the resource it is called on is an indexed resource or identified resource. As of 1.0.0, there is only one list resource: namespace resources (such as sounds.json). Using the incorrect method will throw an exception.

For Identified Resources, the eventName is not used for the Identifier. Instead, the identifier is passed with the JsonElement.

Old Example

() -> {
JsonElement createdJson = /* json */;
return createdJson;
}

New Example

(context) -> {
JsonElement createdJson = /* json */;
context.createResource(/* resourceId */, createdJson);
}

Deletion Events

To delete a resource, call EventContext#markForDeletion with the parameter shouldDelete set to true. Resources are now deleted at the end of resource runtime, which is when all resources have been processed for that resource type. This means other events can still interact with the resource after it is marked for deletion and even cancel its deletion by passing false.

Old Example

() -> {
return true;
}

New Example

(context) -> {
context.markForDeletion(true);
}

Advanced Events

There are now two constructors for the ResourceReference:

ResourceReference(int priority, String resourceId, String referenceId, int ordinal);
ResourceReference(int priority, String resourceId, String referenceId);

Although both resourceId and referenceId are taken as Strings, they are stilled converted to Identifers when the reference is processed.

the method BuiltResourceReference#consume has been replaced with BuiltResourceReference#retrieve:

Optional<JsonElement> retrieve();

Resources are now cleared at the end of event runtime instead of when the resource is consumed. However, the resource may be unavailable if the reference had not been fulfilled yet or the resource doesn't exist.

BuiltResourceReferences are now gotten through the EventContext#getReference method which has a parameter for a string. The string is to be the string equivalent of the referenceId.

Old Example

(elem, references) -> {
BuiltResourceReference ref = references.get(/* referenceId */);
}

New Example

(context) -> {
BuiltResourceReference ref = context.getReference(/* referenceId */);
}

Mixson APT Entrypoint (Fabric only)

The entrypoint for the Mixson annotation processor was renamed from mixsonAPT to mixson. This was an oversight during development that wasn't meant to be shipped.

Old Example

{
...
"custom": {
"mixsonAPT": [
"path.to.the.Class"
]
}
...
}

Updated Example

{
...
"custom": {
"mixson": [
"path.to.the.Class"
]
}
...
}

Events

All annotation events have been replaced with @MixsonEvent and @GenerativeMixsonEvent. These annotations act the same as the old ones besides the method definition now always having an EventContext parameter.

Old Example

@ModificationEvent(value = "resourceId")
private static void modid$eventId(JsonElement elem) {
// content here
}

Updated Example

@MixsonEvent(value = "resourceId")
private static void modid$eventId(EventContext context) {
JsonElement elem = context.getFile();
// content here
}

Misc changes

Mixson#removeEvnts now takes in UUID instead of Identifier. the UUID is gotten from the registration method when the event was registered.

the assertEventRan methods were removed.