更新到1.16后替换物品模型时报空指

USS.Shenzhou


版本信息
你使用的系统:win10 2004 x64
你是用的JDK: 8u251 x64
你使用的IDE:IntelliJ IDEA
你使用的IDE版本:2020.2
Forge版本:34.1.0
Minecraft版本:1.16.3
Mapping 文件版本: 0916-1.16.2

错误情况简述
1.15更到1.16之后,在替换item拿在手上的模型时报错,具体方法是ForgeHooksClient.handlePerspective,下了个断点结果如图


试着自己找是什么地方有问题,但是没找到 :sweat:

报错日志

[22:17:19] [Render thread/FATAL] [minecraft/Minecraft]: Unreported exception thrown!
java.lang.NullPointerException: null
	at net.minecraftforge.client.ForgeHooksClient.handlePerspective(ForgeHooksClient.java:568) ~[forge-1.16.3-34.1.0_mapped_snapshot_20200916-1.16.2-recomp.jar:?] {re:classloading}
	at com.ussshenzhou.rainbow6.util.InventoryModelReplace$2.handlePerspective(InventoryModelReplace.java:138) ~[classes/:?] {re:classloading}
	at net.minecraftforge.client.ForgeHooksClient.handleCameraTransforms(ForgeHooksClient.java:318) ~[forge-1.16.3-34.1.0_mapped_snapshot_20200916-1.16.2-recomp.jar:?] {re:classloading}
	at net.minecraft.client.renderer.ItemRenderer.renderItem(ItemRenderer.java:98) ~[forge-1.16.3-34.1.0_mapped_snapshot_20200916-1.16.2-recomp.jar:?] {re:classloading,pl:accesstransformer:B,pl:runtimedistcleaner:A}
	at net.minecraft.client.renderer.ItemRenderer.renderItem(ItemRenderer.java:207) ~[forge-1.16.3-34.1.0_mapped_snapshot_20200916-1.16.2-recomp.jar:?] {re:classloading,pl:accesstransformer:B,pl:runtimedistcleaner:A}
	at net.minecraft.client.renderer.FirstPersonRenderer.renderItemSide(FirstPersonRenderer.java:50) ~[forge-1.16.3-34.1.0_mapped_snapshot_20200916-1.16.2-recomp.jar:?] {re:classloading,pl:runtimedistcleaner:A}
	at net.minecraft.client.renderer.FirstPersonRenderer.renderItemInFirstPerson(FirstPersonRenderer.java:393) ~[forge-1.16.3-34.1.0_mapped_snapshot_20200916-1.16.2-recomp.jar:?] {re:classloading,pl:runtimedistcleaner:A}
	at net.minecraft.client.renderer.FirstPersonRenderer.renderItemInFirstPerson(FirstPersonRenderer.java:247) ~[forge-1.16.3-34.1.0_mapped_snapshot_20200916-1.16.2-recomp.jar:?] {re:classloading,pl:runtimedistcleaner:A}
	at net.minecraft.client.renderer.GameRenderer.renderHand(GameRenderer.java:381) ~[forge-1.16.3-34.1.0_mapped_snapshot_20200916-1.16.2-recomp.jar:?] {re:classloading,pl:accesstransformer:B,pl:runtimedistcleaner:A}
	at net.minecraft.client.renderer.GameRenderer.renderWorld(GameRenderer.java:625) ~[forge-1.16.3-34.1.0_mapped_snapshot_20200916-1.16.2-recomp.jar:?] {re:classloading,pl:accesstransformer:B,pl:runtimedistcleaner:A}
	at net.minecraft.client.renderer.GameRenderer.updateCameraAndRender(GameRenderer.java:437) ~[forge-1.16.3-34.1.0_mapped_snapshot_20200916-1.16.2-recomp.jar:?] {re:classloading,pl:accesstransformer:B,pl:runtimedistcleaner:A}
	at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:979) ~[forge-1.16.3-34.1.0_mapped_snapshot_20200916-1.16.2-recomp.jar:?] {re:classloading,pl:accesstransformer:B,pl:runtimedistcleaner:A}
	at net.minecraft.client.Minecraft.run(Minecraft.java:589) ~[forge-1.16.3-34.1.0_mapped_snapshot_20200916-1.16.2-recomp.jar:?] {re:classloading,pl:accesstransformer:B,pl:runtimedistcleaner:A}
	at net.minecraft.client.main.Main.main(Main.java:184) ~[forge-1.16.3-34.1.0_mapped_snapshot_20200916-1.16.2-recomp.jar:?] {re:classloading,pl:runtimedistcleaner:A}
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_251] {}
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_251] {}
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_251] {}
	at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_251] {}
	at net.minecraftforge.userdev.FMLUserdevClientLaunchProvider.lambda$launchService$0(FMLUserdevClientLaunchProvider.java:52) ~[forge-1.16.3-34.1.0_mapped_snapshot_20200916-1.16.2-recomp.jar:?] {}
	at cpw.mods.modlauncher.LaunchServiceHandlerDecorator.launch(LaunchServiceHandlerDecorator.java:37) [modlauncher-7.0.1.jar:?] {}
	at cpw.mods.modlauncher.LaunchServiceHandler.launch(LaunchServiceHandler.java:54) [modlauncher-7.0.1.jar:?] {}
	at cpw.mods.modlauncher.LaunchServiceHandler.launch(LaunchServiceHandler.java:72) [modlauncher-7.0.1.jar:?] {}
	at cpw.mods.modlauncher.Launcher.run(Launcher.java:81) [modlauncher-7.0.1.jar:?] {}
	at cpw.mods.modlauncher.Launcher.main(Launcher.java:65) [modlauncher-7.0.1.jar:?] {}
	at net.minecraftforge.userdev.LaunchTesting.main(LaunchTesting.java:105) [forge-1.16.3-34.1.0_mapped_snapshot_20200916-1.16.2-recomp.jar:?] {}

相关代码
InventoryModelReplace.java
有俩物品要换模型 所以只看一半就好了 内容和错误都是一样的

@Mod.EventBusSubscriber(bus = Mod.EventBusSubscriber.Bus.MOD,value = Dist.CLIENT)
public class InventoryModelReplace {
    @SubscribeEvent
    public static void onModelLoad(FMLClientSetupEvent event){
        ModelLoader.addSpecialModel(new ModelResourceLocation(ModItems.reinforcement.getRegistryName()+"_hand","inventory"));
        ModelLoader.addSpecialModel(new ModelResourceLocation(ModItems.blackMirrorItem.getRegistryName()+"_hand","inventory"));
    }
    @SubscribeEvent
    public static void onModelBake(ModelBakeEvent event){
        Map<ResourceLocation, IBakedModel> modelMap = event.getModelRegistry();
        ResourceLocation reinforcement = ModItems.reinforcement.getRegistryName();
        ResourceLocation reinforcementHand = new ModelResourceLocation(reinforcement+"_hand","inventory");
        ResourceLocation reinforcementInventory = new ModelResourceLocation(reinforcement,"inventory");
        IBakedModel reinforcementHandModel = modelMap.get(reinforcementHand);
        IBakedModel reinforcementDefaultModel = modelMap.get(reinforcementInventory);

        IBakedModel reinforcementModelWrapper = new IBakedModel() {
            @Override
            public List<BakedQuad> getQuads(@Nullable BlockState state, @Nullable Direction side, Random rand) {
                return reinforcementDefaultModel.getQuads(state, side, rand);
            }

            @Override
            public boolean isAmbientOcclusion() {
                return reinforcementDefaultModel.isAmbientOcclusion();
            }

            @Override
            public boolean isGui3d() {
                return reinforcementDefaultModel.isGui3d();
            }

            @Override
            public boolean isSideLit() {
                return reinforcementDefaultModel.isSideLit();
            }

            @Override
            public boolean isBuiltInRenderer() {
                return reinforcementDefaultModel.isBuiltInRenderer();
            }

            @Override
            public TextureAtlasSprite getParticleTexture() {
                return reinforcementDefaultModel.getParticleTexture();
            }

            @Override
            public ItemOverrideList getOverrides() {
                return reinforcementDefaultModel.getOverrides();
            }

            @Override
            public IBakedModel handlePerspective(ItemCameraTransforms.TransformType cameraTransformType, MatrixStack mat) {
                IBakedModel reinforcementModelToUse = reinforcementDefaultModel;
                if (cameraTransformType == ItemCameraTransforms.TransformType.FIRST_PERSON_LEFT_HAND||cameraTransformType== ItemCameraTransforms.TransformType.FIRST_PERSON_RIGHT_HAND||cameraTransformType== ItemCameraTransforms.TransformType.THIRD_PERSON_LEFT_HAND||cameraTransformType== ItemCameraTransforms.TransformType.THIRD_PERSON_RIGHT_HAND){
                    reinforcementModelToUse = reinforcementHandModel;
                }
                return ForgeHooksClient.handlePerspective(reinforcementModelToUse,cameraTransformType,mat);
            }


        };
        ResourceLocation blackMirrorItem = ModItems.blackMirrorItem.getRegistryName();
        ResourceLocation blackMirrorItemHand = new ModelResourceLocation(blackMirrorItem+"_hand","inventory");
        ResourceLocation blackMirrorItemInventory = new ModelResourceLocation(blackMirrorItem,"inventory");
        IBakedModel blackMirrorItemHandModel = modelMap.get(blackMirrorItemHand);
        IBakedModel blackMirrorItemDefaultModel = modelMap.get(blackMirrorItemInventory);

        IBakedModel blackMirrorItemModelWrapper = new IBakedModel() {
            @Override
            public List<BakedQuad> getQuads(@Nullable BlockState state, @Nullable Direction side, Random rand) {
                return blackMirrorItemDefaultModel.getQuads(state, side, rand);
            }

            @Override
            public boolean isAmbientOcclusion() {
                return blackMirrorItemDefaultModel.isAmbientOcclusion();
            }

            @Override
            public boolean isGui3d() {
                return blackMirrorItemDefaultModel.isGui3d();
            }

            @Override
            public boolean isSideLit() {
                return blackMirrorItemDefaultModel.isSideLit();
            }

            @Override
            public boolean isBuiltInRenderer() {
                return blackMirrorItemDefaultModel.isBuiltInRenderer();
            }

            @Override
            public TextureAtlasSprite getParticleTexture() {
                return blackMirrorItemDefaultModel.getParticleTexture();
            }

            @Override
            public ItemOverrideList getOverrides() {
                return blackMirrorItemDefaultModel.getOverrides();
            }

            @Override
            public IBakedModel handlePerspective(ItemCameraTransforms.TransformType cameraTransformType, MatrixStack mat) {
                IBakedModel blackMirrorItemModelToUse = blackMirrorItemDefaultModel;
                if (cameraTransformType == ItemCameraTransforms.TransformType.FIRST_PERSON_LEFT_HAND||cameraTransformType== ItemCameraTransforms.TransformType.FIRST_PERSON_RIGHT_HAND||cameraTransformType== ItemCameraTransforms.TransformType.THIRD_PERSON_LEFT_HAND||cameraTransformType== ItemCameraTransforms.TransformType.THIRD_PERSON_RIGHT_HAND){
                    blackMirrorItemModelToUse = blackMirrorItemHandModel;
                }
                return ForgeHooksClient.handlePerspective(blackMirrorItemModelToUse,cameraTransformType,mat);
            }


        };
        modelMap.put(blackMirrorItemInventory,blackMirrorItemModelWrapper);
        modelMap.put(reinforcementInventory,reinforcementModelWrapper);
    }
}

FledgeXu


你在ForgeHooksClient.handlePerspective里打个断点,然后看看是哪个类为null了,然后加个判断就行了……


USS.Shenzhou


噢噢我找到问题了。ModelLoader.addSpecialModel在1.15写在FMLClientSetupEvent下,1.16改到了ModelRegistryEvent:sweat:1.16如果写在FMLClientSetupEvent下的话还是会被执行,但是没什么用…


system


该主题在最后一个回复创建后7天后自动关闭。不再允许新的回复。