Gilly7CE / Carpet-Addons-Not-Found

Addons for the Fabric Carpet mod
MIT License
6 stars 0 forks source link

Refactor PhantomSpawnerMixin to be more compatible with other mods #129

Closed Gilly7CE closed 1 year ago

Gilly7CE commented 1 year ago

PhantomSpawnerMixin was failing to load due to incompatibility with essential addons. It has its own mixin redirect targeting the same method we were. Refactoring our code for our phantom spawning rules has now allowed us to target the direct invocation of ServerWorld.getPlayers and prevent any loop for a player where our phantom spawning rules determine it should be disabled. This is still a redirect, but hopefully will mean being more compatible with other mods. The refactoring also allows us to more easily change this mixin in the future if another issue crops up, and makes it more extensible to other "disabling" type rules we might introduce for phantoms.

The refactored code leverages the "chain of responsibility" pattern to determine whether phantoms should spawn around a particular player. Each "handler" checks whether the player meets its specific conditions for its corresponding rule. If the handler finds the phantoms should not spawn then the chain is broken and no phantoms shall spawn around the player. The order of this chain is as follows (expressed as the carpet rules):

This order has been chosen based on the priority each rule should have.

Fixes #123