emilyploszaj / emi

A featureful and accessible item and recipe viewer
MIT License
220 stars 46 forks source link

Bootstrap plugins during Datagen #537

Open pupnewfster opened 1 month ago

pupnewfster commented 1 month ago

The main use case I have for this is to allow for using EmiIngredientSerializer#getSerialized and EmiIngredientSerializer#getDeserialized as part of my datagen, in order to generate EMI alias files

At least on Neo, you probably could hook it at similarly to what I got CraftTweaker to do quite a while back: https://github.com/CraftTweaker/CraftTweaker/blob/1.20.4/neoforge/src/main/java/com/blamejared/crafttweaker/impl/event/CTModEventHandler.java#L47-L61 The different being you would do GatherDataEvent#includeClient instead of includeServer, and the implementation could basically call the reload handling stuff to make sure that all plugins have been initialized with EmiPlugin#initialize. One thing to note is that recipes and tags won't be loaded, so I don't know if you want to do the full loading or just a subset that only handles the initialize part. Also the reason the event is set to highest for event priority in the CrT example is to ensure it happens before other mods end up having their datagen get added (so it is important that the EMI hook also sets the priority to high or highest).

My current base datagen provider that manually is bootstrapping the Emi Serializers: https://gist.github.com/pupnewfster/b583c2c896f553a87fc40410460dc810 and how I use EmiIngredientSerializer in writing a codec for EmiIngredient