Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

[SOLVED] [1.17.1] Issues with Skull Rendering (again...)


uSkizzik
 Share

Recommended Posts

You'll have to loop through all entity renderers at startup. Check if it is a LivingEntityRenderer. If so, get its render layers (LivingEntityRenderer#layers using reflection) and loop through them as well. Check if any of them is a CustomHeadLayer. If so, get its CustomHeadLayer#skullModels field and put your model in there as well.

Link to comment
Share on other sites

3 minutes ago, diesieben07 said:

You'll have to loop through all entity renderers at startup. Check if it is a LivingEntityRenderer. If so, get its render layers (LivingEntityRenderer#layers using reflection) and loop through them as well. Check if any of them is a CustomHeadLayer. If so, get its CustomHeadLayer#skullModels field and put your model in there as well.

How do I get all entity renderers though?
Also, is FMLClientSetupEvent the correct event or do I need another one?

Link to comment
Share on other sites

2 minutes ago, uSkizzik said:

Also, is FMLClientSetupEvent the correct event or do I need another one?

EntityRenderersEvent.AddLayers and use EventPriority.LOWEST so that your handler runs last (after mods have potentially added their custom layers).

2 minutes ago, uSkizzik said:

How do I get all entity renderers though?

EntityRenderDispatcher#renderers and EntityRenderDispatcher#getSkinMap.

Link to comment
Share on other sites

5 minutes ago, uSkizzik said:

Quick question: How do I get an instance of EntityRenderDispatcher?

Your IDE is your friend. Search for references. The most interesting results will be in "method return type" and "field declaration" as by calling a method with that return type you have an instance and a field will also store an instance. In this case this will reveal the method Minecraft#getEntityRenderDispatcher.

Link to comment
Share on other sites

So, I'm still getting the same crash which means that for some reason this thing is still not using my models.
Here's my code:

    @SubscribeEvent(priority = EventPriority.LOWEST)
    public void registerSkullPlayerHeadLayers(EntityRenderersEvent.AddLayers event) {
        Map<EntityType<?>, EntityRenderer<?>> renderers = Minecraft.getInstance().getEntityRenderDispatcher().renderers;
        for(Map.Entry<EntityType<?>, EntityRenderer<?>> renderer : renderers.entrySet()) {
            if (renderer.getValue() instanceof LivingEntityRenderer) {
                List<? extends RenderLayer<?, ?>> layers = ((LivingEntityRenderer<?, ?>) renderer.getValue()).layers;
                for (RenderLayer<?, ?> layer : layers) {
                    if (layer instanceof CustomHeadLayer) {
                        ((CustomHeadLayer) layer).skullModels.put(PA_TileEntities.CustomSkullTypes.SKIZZIK, new PA_SkullModel(Minecraft.getInstance().getEntityModels().bakeLayer(PA_ModelLayers.SKIZZIK_HEAD_LAYER)));
                        ((CustomHeadLayer) layer).skullModels.put(PA_TileEntities.CustomSkullTypes.SKIZZIK_WITH_GEMS, new PA_SkullModel(Minecraft.getInstance().getEntityModels().bakeLayer(PA_ModelLayers.SKIZZIK_HEAD_WITH_GEMS_LAYER)));
                    }
                }
            }
        }
    }

 

Link to comment
Share on other sites

5 minutes ago, diesieben07 said:

Is the event called? Did you register it properly to the correct event bus?

You also forgot EntityRenderDispatcher#getSkinMap, which is where the player renderers are stored.

1. I forgot to add the bus subscriber (@Mod.EventBusSubscriber(modid = ProjectApple.MOD_ID, bus = Mod.EventBusSubscriber.Bus.MOD))
2. What am I supposed to do with the skin map exactly?

Link to comment
Share on other sites

3 minutes ago, diesieben07 said:

It gives you the player renderers, which you need to treat the same way you do with the other renderers.

This is the crash that happens when the game tries to render a zombie with my custom skull on it:

Spoiler

java.lang.NullPointerException: Cannot invoke "net.minecraft.client.model.SkullModelBase.setupAnim(float, float, float)" because "p_173670_" is null
    at net.minecraft.client.renderer.blockentity.SkullBlockRenderer.renderSkull(SkullBlockRenderer.java:85) ~[forge-1.17.1-37.0.15_mapped_official_1.17.1-recomp.jar%2374!:?] {re:classloading,pl:accesstransformer:B,pl:runtimedistcleaner:A}
    at net.minecraft.client.renderer.entity.layers.CustomHeadLayer.render(CustomHeadLayer.java:87) ~[forge-1.17.1-37.0.15_mapped_official_1.17.1-recomp.jar%2374!:?] {re:classloading,pl:accesstransformer:B,pl:runtimedistcleaner:A}
    at net.minecraft.client.renderer.entity.layers.CustomHeadLayer.render(CustomHeadLayer.java:33) ~[forge-1.17.1-37.0.15_mapped_official_1.17.1-recomp.jar%2374!:?] {re:classloading,pl:accesstransformer:B,pl:runtimedistcleaner:A}
    at net.minecraft.client.renderer.entity.LivingEntityRenderer.render(LivingEntityRenderer.java:126) ~[forge-1.17.1-37.0.15_mapped_official_1.17.1-recomp.jar%2374!:?] {re:classloading,pl:accesstransformer:B,pl:runtimedistcleaner:A}
    at net.minecraft.client.renderer.entity.MobRenderer.render(MobRenderer.java:42) ~[forge-1.17.1-37.0.15_mapped_official_1.17.1-recomp.jar%2374!:?] {re:classloading,pl:runtimedistcleaner:A}
    at net.minecraft.client.renderer.entity.MobRenderer.render(MobRenderer.java:20) ~[forge-1.17.1-37.0.15_mapped_official_1.17.1-recomp.jar%2374!:?] {re:classloading,pl:runtimedistcleaner:A}
    at net.minecraft.client.renderer.entity.EntityRenderDispatcher.render(EntityRenderDispatcher.java:129) ~[forge-1.17.1-37.0.15_mapped_official_1.17.1-recomp.jar%2374!:?] {re:classloading,pl:accesstransformer:B,pl:runtimedistcleaner:A}
    at net.minecraft.client.renderer.LevelRenderer.renderEntity(LevelRenderer.java:1280) ~[forge-1.17.1-37.0.15_mapped_official_1.17.1-recomp.jar%2374!:?] {re:classloading,pl:runtimedistcleaner:A}
    at net.minecraft.client.renderer.LevelRenderer.renderLevel(LevelRenderer.java:1076) ~[forge-1.17.1-37.0.15_mapped_official_1.17.1-recomp.jar%2374!:?] {re:classloading,pl:runtimedistcleaner:A}
    at net.minecraft.client.renderer.GameRenderer.renderLevel(GameRenderer.java:1050) ~[forge-1.17.1-37.0.15_mapped_official_1.17.1-recomp.jar%2374!:?] {re:classloading,pl:accesstransformer:B,pl:runtimedistcleaner:A}
    at net.minecraft.client.renderer.GameRenderer.render(GameRenderer.java:830) ~[forge-1.17.1-37.0.15_mapped_official_1.17.1-recomp.jar%2374!:?] {re:classloading,pl:accesstransformer:B,pl:runtimedistcleaner:A}
    at net.minecraft.client.Minecraft.runTick(Minecraft.java:1039) ~[forge-1.17.1-37.0.15_mapped_official_1.17.1-recomp.jar%2374!:?] {re:classloading,pl:accesstransformer:B,pl:runtimedistcleaner:A}
    at net.minecraft.client.Minecraft.run(Minecraft.java:659) ~[forge-1.17.1-37.0.15_mapped_official_1.17.1-recomp.jar%2374!:?] {re:classloading,pl:accesstransformer:B,pl:runtimedistcleaner:A}
    at net.minecraft.client.main.Main.main(Main.java:186) ~[forge-1.17.1-37.0.15_mapped_official_1.17.1-recomp.jar%2374!:?] {re:classloading,pl:runtimedistcleaner:A}
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:?] {}
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:78) ~[?:?] {}
    at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:?] {}
    at java.lang.reflect.Method.invoke(Method.java:567) ~[?:?] {}
    at net.minecraftforge.fml.loading.targets.ForgeClientUserdevLaunchHandler.lambda$launchService$0(ForgeClientUserdevLaunchHandler.java:38) ~[fmlloader-1.17.1-37.0.15.jar%233!:?] {}
    at cpw.mods.modlauncher.LaunchServiceHandlerDecorator.launch(LaunchServiceHandlerDecorator.java:37) [modlauncher-9.0.7.jar%238!:?] {}
    at cpw.mods.modlauncher.LaunchServiceHandler.launch(LaunchServiceHandler.java:53) [modlauncher-9.0.7.jar%238!:?] {}
    at cpw.mods.modlauncher.LaunchServiceHandler.launch(LaunchServiceHandler.java:71) [modlauncher-9.0.7.jar%238!:?] {}
    at cpw.mods.modlauncher.Launcher.run(Launcher.java:106) [modlauncher-9.0.7.jar%238!:?] {}
    at cpw.mods.modlauncher.Launcher.main(Launcher.java:77) [modlauncher-9.0.7.jar%238!:?] {}
    at cpw.mods.modlauncher.BootstrapLaunchConsumer.accept(BootstrapLaunchConsumer.java:26) [modlauncher-9.0.7.jar%238!:?] {}
    at cpw.mods.modlauncher.BootstrapLaunchConsumer.accept(BootstrapLaunchConsumer.java:23) [modlauncher-9.0.7.jar%238!:?] {}
    at cpw.mods.bootstraplauncher.BootstrapLauncher.main(BootstrapLauncher.java:89) [bootstraplauncher-0.1.16.jar:?] {}

Why doesn't it register my custom models?
This is the thing I placed before the start of the class:

@Mod.EventBusSubscriber(modid = ProjectApple.MOD_ID, bus = Mod.EventBusSubscriber.Bus.MOD)

And this is the method I use to register the models:

@SubscribeEvent(priority = EventPriority.LOWEST)
    public void registerSkullPlayerHeadLayers(EntityRenderersEvent.AddLayers event) {
        Map<EntityType<?>, EntityRenderer<?>> renderers = Minecraft.getInstance().getEntityRenderDispatcher().renderers;
        for(Map.Entry<EntityType<?>, EntityRenderer<?>> renderer : renderers.entrySet()) {
            if (renderer.getValue() instanceof LivingEntityRenderer) {
                List<? extends RenderLayer<?, ?>> layers = ((LivingEntityRenderer<?, ?>) renderer.getValue()).layers;
                for (RenderLayer<?, ?> layer : layers) {
                    if (layer instanceof CustomHeadLayer) {
                        ((CustomHeadLayer) layer).skullModels.put(PA_TileEntities.CustomSkullTypes.SKIZZIK, new PA_SkullModel(Minecraft.getInstance().getEntityModels().bakeLayer(PA_ModelLayers.SKIZZIK_HEAD_LAYER)));
                        ((CustomHeadLayer) layer).skullModels.put(PA_TileEntities.CustomSkullTypes.SKIZZIK_WITH_GEMS, new PA_SkullModel(Minecraft.getInstance().getEntityModels().bakeLayer(PA_ModelLayers.SKIZZIK_HEAD_WITH_GEMS_LAYER)));
                    }
                }
            }
        }

        Map<String, EntityRenderer<? extends Player>> skins = Minecraft.getInstance().getEntityRenderDispatcher().getSkinMap();
        for(Map.Entry<String, EntityRenderer<? extends Player>> renderer : skins.entrySet()) {
            if (renderer.getValue() instanceof LivingEntityRenderer) {
                List<? extends RenderLayer<?, ?>> layers = ((LivingEntityRenderer<?, ?>) renderer.getValue()).layers;
                for (RenderLayer<?, ?> layer : layers) {
                    if (layer instanceof CustomHeadLayer) {
                        ((CustomHeadLayer) layer).skullModels.put(PA_TileEntities.CustomSkullTypes.SKIZZIK, new PA_SkullModel(Minecraft.getInstance().getEntityModels().bakeLayer(PA_ModelLayers.SKIZZIK_HEAD_LAYER)));
                        ((CustomHeadLayer) layer).skullModels.put(PA_TileEntities.CustomSkullTypes.SKIZZIK_WITH_GEMS, new PA_SkullModel(Minecraft.getInstance().getEntityModels().bakeLayer(PA_ModelLayers.SKIZZIK_HEAD_WITH_GEMS_LAYER)));
                    }
                }
            }
        }
    }

I used ATs instead of reflection which worked for the block renderer.

Link to comment
Share on other sites

58 minutes ago, uSkizzik said:

EDIT: I solved it by calling the method via the project class. Now I have a new error: https://gist.github.com/uSkizzik/e5079c0a6196a6a213f6255343efa7e8

'java.lang.UnsupportedOperationException' because 'com.google.common.collect.ImmutableMap.put'
you can't put things in a ImmutableMap, you will need to get all objects from the Map and then create a new Map

Edit: you can't use a for-each loop on a ImmutableMap (Minecraft.getInstance().getEntityRenderDispatcher().getSkinMap() will return a ImmutableMap)
you need to create to create a new HashMap and do then the for-each loop (you can use Maps.newHashMap and put Minecraft.getInstance().getEntityRenderDispatcher().getSkinMap() as parameter)

Edited by Luis_ST
Link to comment
Share on other sites

3 hours ago, Luis_ST said:

'java.lang.UnsupportedOperationException' because 'com.google.common.collect.ImmutableMap.put'
you can't put things in a ImmutableMap, you will need to get all objects from the Map and then create a new Map

Edit: you can't use a for-each loop on a ImmutableMap (Minecraft.getInstance().getEntityRenderDispatcher().getSkinMap() will return a ImmutableMap)
you need to create to create a new HashMap and do then the for-each loop (you can use Maps.newHashMap and put Minecraft.getInstance().getEntityRenderDispatcher().getSkinMap() as parameter)

I actually just made a new method to make the new immutable map with my custom models (via ImmutableMap.builder(), like in vanilla) and it worked.

Link to comment
Share on other sites

  • uSkizzik changed the title to [SOLVED] [1.17.1] Issues with Skull Rendering (again...)

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share



×
×
  • Create New...

Important Information

By using this site, you agree to our Privacy Policy.