gnembon / carpet-extra

Extra Features for Carpet Mod
GNU Lesser General Public License v3.0
294 stars 61 forks source link

Improve compatibility of `dispensersToggleThings` by optionally using Fabric API's stub players #302

Open altrisi opened 1 year ago

altrisi commented 1 year ago

Supersedes #283.

This PR makes Carpet Extra use Fabric API's new stub players (confusingly called FakePlayer in the API) for dispensersToggleThings if the API is available. Otherwise, it keeps using null and handling null where vanilla doesn't.

The API access is done via a constant MethodHandle that will directly either call the api or return null. Constant MethodHandles can even be inlined to a plain call, so this should ensure no performance loss vs directly calling the api.

Vs #283, this:

I'll hold on merging until this last point is resolved in Fabric API, but otherwise this is ready.