-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix Figura compatibility #76
base: 1.19
Are you sure you want to change the base?
Conversation
Fabric expects a public constructor with no parameters to be the entrypoint. Figura will later use `build(Avatar)` to run the `private SwitchyFiguraApi(Avatar)` constructor. Should fix sisby-folk#75
I made a pull request to the 1.19 branch specifically since it is listed as the main branch but from what I can see this affects all versions. |
Seems like there's more issues with Figura compat that need addressed. |
This is done by first checking if the avatar has errored and returning if it has. Then the function invocation is wrapped in a try-catch and any errors are redirected to the avatar's Lua runtime.
Considering the idea of turning this compat into a true Figura Event instead. Then users could just do events["SWITCHY.SWITCH"]:register(function(newpreset, oldpreset, enabledmodules)
-- blah blah
end) and it would Just Work™ edit: I have decided to go against that idea mostly because Java is a pain to work with. |
Looks good to us - can you send through the reference / code you had for how proper figura events are set up? we couldl take a look. |
I tried to make the code in the code block below which works fine until it tries to compile FiguraMC has an example of how an event should be set up at The code below defines two events:
package folk.sisby.switchy.client;
import folk.sisby.switchy.client.api.SwitchyClientEvents;
import com.mojang.datafixers.util.Pair;
import org.figuramc.figura.entries.FiguraEvent;
import org.figuramc.figura.entries.annotations.FiguraEventPlugin;
import org.figuramc.figura.lua.LuaWhitelist;
import org.figuramc.figura.lua.api.event.LuaEvent;
import org.figuramc.figura.lua.docs.LuaFieldDoc;
import org.figuramc.figura.avatar.AvatarManager;
import org.figuramc.figura.avatar.Avatar;
import java.util.Collection;
import java.util.List;
@FiguraEventPlugin
public class FiguraSwitchyEvent implements FiguraEvent {
@LuaWhitelist
@LuaFieldDoc("events.switchy.world_switch")
public static LuaEvent WORLD_SWITCH = new LuaEvent();
@LuaWhitelist
@LuaFieldDoc("events.switchy.switch")
public static LuaEvent SWITCH = new LuaEvent();
@Override
public String getID() {
return "switchy";
}
static {
SwitchyClientEvents.SWITCH.register((event) -> {
Avatar avatar = AvatarManager.getAvatarForPlayer(event.player());
if (avatar != null) {
String newPreset = event.currentPreset();
String oldPreset = event.previousPreset();
List<String> enabledModules = event.enabledModules();
avatar.run(WORLD_SWITCH, avatar.worldTick, newPreset, oldPreset, enabledModules);
if (avatar.loaded && avatar.luaRuntime != null && avatar.luaRuntime.getUser() != null)
avatar.run(SWITCH, avatar.tick, newPreset, oldPreset, enabledModules);
}
});
}
@Override
public Collection<Pair<String, LuaEvent>> getEvents() {
return List.of(
new Pair<>("SWITCH", SWITCH),
new Pair<>("WORLD_SWITCH", WORLD_SWITCH)
);
}
} |
Fabric expects a public constructor with no parameters to be the entrypoint.
Figura will later use
build(Avatar)
to run theprivate SwitchyFiguraApi(Avatar)
constructor.From my quick testing this does not cause any issues.
Should fix #75