Customizable Player Models

Customizable Player Models

2M Downloads

Correctly update FirstpersonMod support

tr7zw opened this issue ยท 1 comments

commented

Hey there, I'm the dev of Firstperson Mod and the way CPM currently interacts with the mod is really not good/crashes in with the latest release for 1.16.5-1.20.4. There are calls to FirstPersonModelCore.getWrapper().applyThirdPerson(false), this:

	public static void initPlayerProfile() {
		if(ModList.get().isLoaded("firstpersonmod")) {
			try {
				MethodHandle h = MethodHandles.lookup().unreflectGetter(Class.forName("dev.tr7zw.firstperson.FirstPersonModelCore").getDeclaredField("isRenderingPlayer"));
				PlayerProfile.inFirstPerson = () -> {
					try {
						return (boolean) h.invoke();
					} catch (Throwable e) {
						PlayerProfile.inFirstPerson = () -> false;
						return false;
					}
				};
				PlayerProfile.inFirstPerson.getAsBoolean();
			} catch (Throwable e) {
			}
		}
	}

and just recently added:

public class FirstPersonDetector {

	public static void init() {
		try {
			PlayerProfile.inFirstPerson = () -> FirstPersonModelCore.isRenderingPlayer;
		} catch (Throwable e) {
		}
	}

}

None of these ways are the intended way to check if it's rendering the player in firstperson right now. For over 2 years there has been FirstPersonAPI.isRenderingPlayer() which will return true just for the exact timeframe the player is getting rendered. The API class also has other methods if required like isEnabled(), registerPlayerHandler(which can modify the offsets or dynamically turn the mod on/off) and setEnabled(b). The currently used getWrapper methods are already gone, and with the next update FirstPersonModelCore.isRenderingPlayer will become private(and its already moved to another class). So none of these 3 snippets above will work at all.
I did unify the codebase 1.16.5-1.20.4, so the API class looks and works exactly the same between all these versions. A MethodHandle to dev.tr7zw.firstperson.api.FirstPersonAPI.isRenderingPlayer() is probably all you need.

commented

Registering a PlayerOffsetHandler might be needed if you want to support people with really deformed skins that don't line up at all with how the Vanilla model works(just saw someone in Discord who uses a Dinosaur as a model). In that case you need to calculate the offset of where the model head is to the camera, so the model can be pushed back correctly. Then the camera should be placed on the neck.