From 76f116dc90b705bd7ada72aaec538fd4fbc51cd6 Mon Sep 17 00:00:00 2001 From: Hubry Date: Mon, 24 Feb 2020 19:32:57 +0100 Subject: [PATCH] Check if models were registered to avoid misleading NPE crashes This happens if an error occurs earlier, causing Forge to start aborting loading. Not all things are stopped and not all exceptions are caught gracefully, and if something throws one that crashes the game, a crash report will be generated instead of an error screen appearing. --- .../botania/client/core/handler/MiscellaneousIcons.java | 6 ++++++ .../vazkii/botania/client/core/handler/ModelHandler.java | 4 ++++ 2 files changed, 10 insertions(+) diff --git a/src/main/java/vazkii/botania/client/core/handler/MiscellaneousIcons.java b/src/main/java/vazkii/botania/client/core/handler/MiscellaneousIcons.java index f6d786a3e..fffbdff47 100644 --- a/src/main/java/vazkii/botania/client/core/handler/MiscellaneousIcons.java +++ b/src/main/java/vazkii/botania/client/core/handler/MiscellaneousIcons.java @@ -31,6 +31,7 @@ import vazkii.botania.client.model.LexiconModel; import vazkii.botania.client.model.PlatformModel; import vazkii.botania.client.render.tile.RenderTileCorporeaCrystalCube; import vazkii.botania.client.render.tile.RenderTilePump; +import vazkii.botania.common.Botania; import vazkii.botania.common.item.ModItems; import vazkii.botania.common.item.equipment.bauble.ItemFlightTiara; import vazkii.botania.common.item.relic.ItemKingKey; @@ -90,6 +91,11 @@ public class MiscellaneousIcons { @SubscribeEvent public void onModelBake(ModelBakeEvent evt) { + if (!ModelHandler.registeredModels) { + Botania.LOGGER.error("Additional models failed to register! Aborting baking models to avoid early crashing."); + return; + } + // Water bowl ModelDynBucket bowl = new ModelDynBucket(prefix("items/waterbowl_base"), prefix("items/waterbowl_fluid"), prefix("items/waterbowl_cover"), Fluids.WATER, false, true); IModelState transform = ForgeBlockStateV1.Transforms.get("forge:default-item").get(); diff --git a/src/main/java/vazkii/botania/client/core/handler/ModelHandler.java b/src/main/java/vazkii/botania/client/core/handler/ModelHandler.java index b17f5a3d7..81e19fad2 100644 --- a/src/main/java/vazkii/botania/client/core/handler/ModelHandler.java +++ b/src/main/java/vazkii/botania/client/core/handler/ModelHandler.java @@ -78,8 +78,12 @@ import static vazkii.botania.common.lib.ResourceLocationHelper.prefix; @Mod.EventBusSubscriber(value = Dist.CLIENT, modid = LibMisc.MOD_ID, bus = Mod.EventBusSubscriber.Bus.MOD) public final class ModelHandler { + static boolean registeredModels = false; + @SubscribeEvent public static void registerModels(ModelRegistryEvent evt) { + registeredModels = true; + ModelLoaderRegistry.registerLoader(FloatingFlowerModel.Loader.INSTANCE); ModelLoader.addSpecialModel(new ModelResourceLocation(LibMisc.MOD_ID + ":mana_gun_clip", "inventory")); ModelLoader.addSpecialModel(new ModelResourceLocation(LibMisc.MOD_ID + ":desu_gun", "inventory"));