Origins (Fabric)

Origins (Fabric)

15M Downloads

Suggestion: Make Mixins Event-based

lochnessdragon opened this issue ยท 2 comments

commented

This is just a suggestion, and might require major code rewrite, but I believe that transferring all or some of the mixins to use events would be beneficial to the extendability of the project, as developers could simply add an event callback to listen to mixins they might already be interested in handling. For example, for the ServerPlayerEntity.trySleep() method, if I wanted to implement more logic to prevent players sleeping if they're near another origin, they I would have to write a new mixin and potentially interfere with the regular logic. If the mixin system were event based, though, I would only have to register a callback, and there would be little interference.

Events on the Fabric Wiki:
https://fabricmc.net/wiki/tutorial:events

commented

If you wanted to prevent players from sleeping if they're near another origin, you should (that is, if you're working on an Origins add-on) implement a condition called something like entity_in_radius, which counts entities in radius fulfilling a specified entity_condition, and then compares that count based on a provided comparison and compare_to value. (Kind of similar to the block_in_radius condition).

Then you could just use the existing prevent_sleep power type with the newly implemented condition to do what you want.

However, I appreciate the suggestion and still see the benefits of such a system. Even better would probably be to extract these events from the main mod into a library, such that other mods may rely on it without including all of Origins as a dependency, in order to improve inter-mod compatibility as well.

commented

Yes, I agree with your point. There should be a library that adds a large variety of custom events. I also agree that conditions should be used to change a power based on a nearby player, but I don't believe there is a way to apply a power globally. I would like to avoid manually applying the power for every origin because I want it to work with any Origins addons.