Boson教程11.1节运行出错


版本信息
系统:<Mac OS 1.15.7>
JDK: <1.8.0_272>
IDE:
Forge版本: <1.16.3-34.1.0>
Minecraft版本: <1.16.3>
Mapping 文件版本: <mappings channel: ‘snapshot’, version: ‘20200916-1.16.2’>

错误情况简述
进行渲染时游戏崩溃,在运行 net.minecraft.client.renderer.entity.EntityRendererManager.shouldRender 函数时,进行renders查询没有注册的渲染器

报错日志

[02:28:28] [Render thread/FATAL] [minecraft/Minecraft]: Unreported exception thrown!
java.lang.NullPointerException: null
	at net.minecraft.client.renderer.entity.EntityRendererManager.shouldRender(EntityRendererManager.java:239) ~[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.WorldRenderer.updateCameraAndRender(WorldRenderer.java:1004) ~[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.renderWorld(GameRenderer.java:619) ~[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_272] {}
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_272] {}
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_272] {}
	at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_272] {}
	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:?] {}

相关代码
进行相应渲染器注册后,列表中没有对应的渲染器注册结果:
ClientEventHandler

@Mod.EventBusSubscriber(bus = Mod.EventBusSubscriber.Bus.MOD, value = Dist.CLIENT)
public class ClientEventHandler {
    @SubscribeEvent
    public static void onClientSetUpEvent(FMLClientSetupEvent event) {
        event.enqueueWork(() -> {
            RenderTypeLookup.setRenderLayer(BlockRegistry.glassJar.get(), RenderType.getTranslucent());
            ClientRegistry.bindTileEntityRenderer(TileEntityTypeRegistry.obsidianTERTileEntity.get(), ObsidianTER::new);
            RenderingRegistry.registerEntityRenderingHandler(EntityTypeRegistry.flyingSwordEntity.get(), FlyingSwordRender::new);
        });
    }
}

FledgeXu


你这个EntityType注册了吗?请你补充一下这块的注册代码。



@Mod(Utils.MOD_ID)
public class Rocket {
    public Rocket() {
        IEventBus eventBus = FMLJavaModLoadingContext.get().getModEventBus();
        //eventBus.addListener(ClientEventHandler::onClientSetUpEvent);
        ItemRegistry.ITEMS.register(eventBus);
        BlockRegistry.BLOCKS.register(eventBus);
        TileEntityTypeRegistry.TILE_ENTITIES.register(eventBus);
        EntityTypeRegistry.ENTITY_TYPES.register(eventBus);
    }
}
public class EntityTypeRegistry {
    public static final DeferredRegister<EntityType<?>> ENTITY_TYPES = DeferredRegister.create(ForgeRegistries.ENTITIES, Utils.MOD_ID);
    public static final RegistryObject<EntityType<FlyingSwordEntity>> flyingSwordEntity = ENTITY_TYPES.register("flying_sword", () -> EntityType.Builder.create(FlyingSwordEntity::new, EntityClassification.MISC).size(3, 0.5F).build("flying_sword"));
}


@Mod.EventBusSubscriber(bus = Mod.EventBusSubscriber.Bus.MOD, value = Dist.CLIENT)
public class ClientEventHandler {
    @SubscribeEvent
    public static void onClientSetUpEvent(FMLClientSetupEvent event) {
        event.enqueueWork(() -> {
            RenderTypeLookup.setRenderLayer(BlockRegistry.glassJar.get(), RenderType.getTranslucent());
            ClientRegistry.bindTileEntityRenderer(TileEntityTypeRegistry.obsidianTERTileEntity.get(), ObsidianTER::new);
            //RenderingRegistry.registerEntityRenderingHandler(EntityTypeRegistry.flyingSwordEntity.get(), FlyingSwordRender::new);
            Minecraft.getInstance().getRenderManager().register(EntityTypeRegistry.flyingSwordEntity.get(), new FlyingSwordRender(Minecraft.getInstance().getRenderManager()));
        });
    }
}

使用这种方式进行注册renderer,可以正常进入



FledgeXu


 RenderingRegistry.registerEntityRenderingHandler(EntityTypeRegistry.flyingSwordEntity.get(), FlyingSwordRender::new);

event.enqueueWork拿出来就行了。


system


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