FoundationGames / Automobility

A Minecraft mod on the Fabric modloader which aims to add some useful vehicles.
MIT License
49 stars 25 forks source link

[1.19.2+] `onResourceManagerReload` cancelled for mods injecting code on TAIL #52

Open MrCrayfish opened 1 year ago

MrCrayfish commented 1 year ago

I've had someone report that the models in my mod aren't loading, ultimately leading to a crash. I've taken a look into the issue and it seems to stem from your mod. It seems that your Mixin that injects code into the head of onResourceManagerReload is being cancelled afterwards. You can see my mixin here.

I've gone ahead and written an example of compatible code, which doesn't require your mod to cancel the event. If you want to respect the immutability of roots, you can instead apply a ModifyArg to the args of ImmutableMap.copyOf, create a new HashMap, call your loadModels, then just return the map.

@Shadow
private Map<ModelLayerLocation, LayerDefinition> roots;

@Inject(method = "onResourceManagerReload", at = @At(value = "TAIL"))
private void jsonem$loadJsonEntityModels(ResourceManager manager, CallbackInfo ci)
{
    this.roots = new HashMap<>(this.roots);
    JsonEntityModelUtil.loadModels(manager, this.roots);
}

I noticed too that you are calling ForgeHooksClient.loadLayerDefinitions in JsonEntityModelUtil#loadModels, this is unnecessary since this is called in LayerDefinitions#createRoots.

Let me know if you have any questions, I am happy to help with ensuring compatibility.