[1.19.3] Add event before baked models are cached by the BlockModelShaper (#9190)

This commit is contained in:
Dennis C authored and GitHub committed 2022-12-11 20:35:45 +01:00
1 parent 332ed4ab76
commit 069a94f205
3 files changed
+65 -3

No files matched your search

@@ -169,6 +169,7 @@ import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
@@ -471,9 +472,14 @@ public class ForgeHooksClient
return event;
}
public static void onModifyBakingResult(Map<ResourceLocation, BakedModel> models, ModelBakery modelBakery)
{
ModLoader.get().postEvent(new ModelEvent.ModifyBakingResult(models, modelBakery));
}
public static void onModelBake(ModelManager modelManager, Map<ResourceLocation, BakedModel> models, ModelBakery modelBakery)
{
ModLoader.get().postEvent(new ModelEvent.BakingCompleted(modelManager, models, modelBakery));
ModLoader.get().postEvent(new ModelEvent.BakingCompleted(modelManager, Collections.unmodifiableMap(models), modelBakery));
}
public static BakedModel handleCameraTransforms(PoseStack poseStack, BakedModel model, ItemTransforms.TransformType cameraTransformType, boolean applyLeftHandTransform)
@@ -32,9 +32,56 @@ public abstract class ModelEvent extends Event
{
}
/**
* Fired while the {@link ModelManager} is reloading models, after the model registry is set up, but before it's
* passed to the {@link net.minecraft.client.renderer.block.BlockModelShaper} for caching.
*
* <p>
* This event is fired from a worker thread and it is therefore not safe to access anything outside the
* model registry and {@link ModelBakery} provided in this event.<br>
* The {@link ModelManager} firing this event is not fully set up with the latest data when this event fires and
* must therefore not be accessed in this event.
* </p>
*
* <p>This event is not {@linkplain Cancelable cancellable}, and does not {@linkplain HasResult have a result}.</p>
*
* <p>This event is fired on the {@linkplain FMLJavaModLoadingContext#getModEventBus() mod-specific event bus},
* only on the {@linkplain LogicalSide#CLIENT logical client}.</p>
*/
public static class ModifyBakingResult extends ModelEvent implements IModBusEvent
{
private final Map<ResourceLocation, BakedModel> models;
private final ModelBakery modelBakery;
@ApiStatus.Internal
public ModifyBakingResult(Map<ResourceLocation, BakedModel> models, ModelBakery modelBakery)
{
this.models = models;
this.modelBakery = modelBakery;
}
/**
* @return the modifiable registry map of models and their model names
*/
public Map<ResourceLocation, BakedModel> getModels()
{
return models;
}
/**
* @return the model loader
*/
public ModelBakery getModelBakery()
{
return modelBakery;
}
}
/**
* Fired when the {@link ModelManager} is notified of the resource manager reloading.
* Called after model registry is set up, but before it's passed to {@link net.minecraft.client.renderer.block.BlockModelShaper}.
* Called after the model registry is set up and cached in the {@link net.minecraft.client.renderer.block.BlockModelShaper}.<br>
* The model registry given by this event is unmodifiable. To modify the model registry, use
* {@link ModelEvent.ModifyBakingResult} instead.
*
* <p>This event is not {@linkplain Cancelable cancellable}, and does not {@linkplain HasResult have a result}.</p>
*
@@ -64,7 +111,7 @@ public abstract class ModelEvent extends Event
}
/**
* @return the modifiable registry map of models and their model names
* @return an unmodifiable view of the registry map of models and their model names
*/
public Map<ResourceLocation, BakedModel> getModels()
{