Skip to content

Commit

Permalink
Avoid NPE when accessing model manager
Browse files Browse the repository at this point in the history
  • Loading branch information
embeddedt committed Aug 27, 2023
1 parent d21aea0 commit 8b1e2d7
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.google.common.collect.ImmutableList;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.block.model.IBakedModel;
import net.minecraft.client.renderer.block.model.ModelManager;
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
import net.minecraft.util.registry.RegistrySimple;
import net.minecraftforge.client.event.ModelBakeEvent;
Expand All @@ -20,6 +21,7 @@
import java.util.Objects;

public class SafeModelBakeWrapper {
public static ModelManager theManager;
private static final ImmutableList<Pair<String, String>> MOD_BAKE_CLASSES = ImmutableList.<Pair<String, String>>builder()
.add(Pair.of("tschipp.hardcoreitemstages.ItemStageEventHandler", "onModelBakeEvent"))
.build();
Expand Down Expand Up @@ -59,14 +61,14 @@ public static class WrappingHandler {

@SubscribeEvent
public void onDynBake(DynamicModelBakeEvent e) {
if(!(e.location instanceof ModelResourceLocation) || recursion > 0)
if(!(e.location instanceof ModelResourceLocation) || recursion > 0 || SafeModelBakeWrapper.theManager == null)
return;
recursion++;
try {
RegistrySimple<ModelResourceLocation, IBakedModel> reg = new RegistrySimple<>();
reg.putObject((ModelResourceLocation)e.location, e.bakedModel);
ModelBakeEvent event = new ModelBakeEvent(
Minecraft.getMinecraft().getBlockRendererDispatcher().getBlockModelShapes().getModelManager(),
SafeModelBakeWrapper.theManager,
reg,
null
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ public void onResourceManagerReload(IResourceManager resourceManager) {
DynamicBakedModelProvider dynamicBakedModelProvider = new DynamicBakedModelProvider(dynamicModelProvider);
DynamicBakedModelProvider.instance = dynamicBakedModelProvider;
modelRegistry = dynamicBakedModelProvider;
SafeModelBakeWrapper.theManager = (ModelManager)(Object)this;

earlyDetectedTextures = new HashSet<>();

Expand Down

0 comments on commit 8b1e2d7

Please sign in to comment.