Jump to content

Recommended Posts

Posted

I'd like to create an entity like snowball, and tried to use RenderSprite class as a renderer of my entity.

private void doClientStuff(final FMLClientSetupEvent event) {
  ItemRenderer itemRenderer = Minecraft.getInstance().getItemRenderer();
  
  RenderingRegistry.registerEntityRenderingHandler(EntityProactiv.class, new IRenderFactory<EntityProactiv>() {
    @Override
    public Render<? super EntityProactiv> createRenderFor(RenderManager manager) {
      return new RenderSprite<EntityProactiv>(manager, ModItems.proactiv, itemRenderer);
    }
  });
}

(EntityProactive is the entity I'm creating.)

 

However, when I throw the entity in the game, the game crashes on account of NullPointerException.

 

Here is a part of a crash report.

---- Minecraft Crash Report ----
// But it works on my machine.

Time: 19/03/14 16:11
Description: Rendering entity in world

java.lang.NullPointerException: Rendering entity in world
	at net.minecraft.client.renderer.entity.RenderSprite.doRender(RenderSprite.java:41)
	at net.minecraft.client.renderer.entity.RenderManager.renderEntity(RenderManager.java:374)
	at net.minecraft.client.renderer.entity.RenderManager.renderEntityStatic(RenderManager.java:363)
	at net.minecraft.client.renderer.WorldRenderer.renderEntities(WorldRenderer.java:591)
	at net.minecraft.client.renderer.GameRenderer.updateCameraAndRender(GameRenderer.java:844)
	at net.minecraft.client.renderer.GameRenderer.renderWorld(GameRenderer.java:771)
	at net.minecraft.client.renderer.GameRenderer.updateCameraAndRender(GameRenderer.java:635)
	at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:871)
	at net.minecraft.client.Minecraft.run(Minecraft.java:398)
	at net.minecraft.client.main.Main.main(Main.java:117)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at net.minecraftforge.userdev.FMLUserdevClientLaunchProvider.lambda$launchService$0(FMLUserdevClientLaunchProvider.java:55)
	at cpw.mods.modlauncher.LaunchServiceHandlerDecorator.launch(LaunchServiceHandlerDecorator.java:19)
	at cpw.mods.modlauncher.LaunchServiceHandler.launch(LaunchServiceHandler.java:32)
	at cpw.mods.modlauncher.LaunchServiceHandler.launch(LaunchServiceHandler.java:50)
	at cpw.mods.modlauncher.Launcher.run(Launcher.java:56)
	at cpw.mods.modlauncher.Launcher.main(Launcher.java:42)
	at net.minecraftforge.userdev.LaunchTesting.main(LaunchTesting.java:87)


A detailed walkthrough of the error, its code path and all known details is as follows:
---------------------------------------------------------------------------------------

-- Head --
Thread: Client thread
Stacktrace:
	at net.minecraft.client.renderer.entity.RenderSprite.doRender(RenderSprite.java:41)

-- Entity being rendered --
Details:
	Entity Type: examplemod:proactiv (com.example.examplemod.entity.EntityProactiv)
	Entity ID: 734
	Entity Name: entity.examplemod.proactiv
	Entity's Exact location: -136.89, 32.68, 4.36
	Entity's Block location: World: (-137,32,4), Chunk: (at 7,2,4 in -9,0; contains blocks -144,0,0 to -129,255,15), Region: (-1,0; contains chunks -32,0 to -1,31, blocks -512,0,0 to -1,255,511)
	Entity's Momentum: 0.73, -1.35, -0.35
	Entity's Passengers: []
	Entity's Vehicle: ~~ERROR~~ NullPointerException: null

-- Renderer details --
Details:
	Assigned renderer: net.minecraft.client.renderer.entity.RenderSprite@3dad282e
	Location: 0.22,1.15,-0.10 - World: (0,1,-1), Chunk: (at 0,0,15 in 0,-1; contains blocks 0,0,-16 to 15,255,-1), Region: (0,-1; contains chunks 0,-32 to 31,-1, blocks 0,0,-512 to 511,255,-1)
	Rotation: -47.278442
	Delta: 0.29999948
Stacktrace:
	at net.minecraft.client.renderer.entity.RenderManager.renderEntity(RenderManager.java:374)
	at net.minecraft.client.renderer.entity.RenderManager.renderEntityStatic(RenderManager.java:363)
	at net.minecraft.client.renderer.WorldRenderer.renderEntities(WorldRenderer.java:591)
	at net.minecraft.client.renderer.GameRenderer.updateCameraAndRender(GameRenderer.java:844)
	at net.minecraft.client.renderer.GameRenderer.renderWorld(GameRenderer.java:771)

 

Will you tell me the problem of my code?

Posted
11 minutes ago, diesieben07 said:

Obtain the ItemRenderer instance when your IRenderFactory is called.

I modified my code, but it doesn't work...

private void doClientStuff(final FMLClientSetupEvent event) {
  RenderingRegistry.registerEntityRenderingHandler(EntityProactiv.class, new IRenderFactory<EntityProactiv>() {
    ItemRenderer itemRenderer = Minecraft.getInstance().getItemRenderer();
    @Override
    public Render<? super EntityProactiv> createRenderFor(RenderManager manager) {
      return new RenderSprite<EntityProactiv>(manager, ModItems.proactiv, itemRenderer);
    }
  });
}
---- Minecraft Crash Report ----
// Who set us up the TNT?

Time: 19/03/14 18:45
Description: Rendering entity in world

java.lang.NullPointerException: Rendering entity in world
	at net.minecraft.client.renderer.entity.RenderSprite.doRender(RenderSprite.java:41)
	at net.minecraft.client.renderer.entity.RenderManager.renderEntity(RenderManager.java:374)
	at net.minecraft.client.renderer.entity.RenderManager.renderEntityStatic(RenderManager.java:363)
	at net.minecraft.client.renderer.WorldRenderer.renderEntities(WorldRenderer.java:591)
	at net.minecraft.client.renderer.GameRenderer.updateCameraAndRender(GameRenderer.java:844)
	at net.minecraft.client.renderer.GameRenderer.renderWorld(GameRenderer.java:771)
	at net.minecraft.client.renderer.GameRenderer.updateCameraAndRender(GameRenderer.java:635)
	at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:871)
	at net.minecraft.client.Minecraft.run(Minecraft.java:398)
	at net.minecraft.client.main.Main.main(Main.java:117)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at net.minecraftforge.userdev.FMLUserdevClientLaunchProvider.lambda$launchService$0(FMLUserdevClientLaunchProvider.java:55)
	at cpw.mods.modlauncher.LaunchServiceHandlerDecorator.launch(LaunchServiceHandlerDecorator.java:19)
	at cpw.mods.modlauncher.LaunchServiceHandler.launch(LaunchServiceHandler.java:32)
	at cpw.mods.modlauncher.LaunchServiceHandler.launch(LaunchServiceHandler.java:50)
	at cpw.mods.modlauncher.Launcher.run(Launcher.java:56)
	at cpw.mods.modlauncher.Launcher.main(Launcher.java:42)
	at net.minecraftforge.userdev.LaunchTesting.main(LaunchTesting.java:87)


A detailed walkthrough of the error, its code path and all known details is as follows:
---------------------------------------------------------------------------------------

-- Head --
Thread: Client thread
Stacktrace:
	at net.minecraft.client.renderer.entity.RenderSprite.doRender(RenderSprite.java:41)

-- Entity being rendered --
Details:
	Entity Type: examplemod:proactiv (com.example.examplemod.entity.EntityProactiv)
	Entity ID: 1210
	Entity Name: entity.examplemod.proactiv
	Entity's Exact location: -213.04, 76.52, -299.91
	Entity's Block location: World: (-214,76,-300), Chunk: (at 10,4,4 in -14,-19; contains blocks -224,0,-304 to -209,255,-289), Region: (-1,-1; contains chunks -32,-32 to -1,-1, blocks -512,0,-512 to -1,255,-1)
	Entity's Momentum: -0.39, -1.03, -1.05
	Entity's Passengers: []
	Entity's Vehicle: ~~ERROR~~ NullPointerException: null

-- Renderer details --
Details:
	Assigned renderer: net.minecraft.client.renderer.entity.RenderSprite@1cd50f37
	Location: 0.00,-1.82,0.00 - World: (0,-2,0), Chunk: (at 0,-1,0 in 0,0; contains blocks 0,0,0 to 15,255,15), Region: (0,0; contains chunks 0,0 to 31,31, blocks 0,0,0 to 511,255,511)
	Rotation: -43.59375
	Delta: 0.6999997
Stacktrace:
	at net.minecraft.client.renderer.entity.RenderManager.renderEntity(RenderManager.java:374)
	at net.minecraft.client.renderer.entity.RenderManager.renderEntityStatic(RenderManager.java:363)
	at net.minecraft.client.renderer.WorldRenderer.renderEntities(WorldRenderer.java:591)
	at net.minecraft.client.renderer.GameRenderer.updateCameraAndRender(GameRenderer.java:844)
	at net.minecraft.client.renderer.GameRenderer.renderWorld(GameRenderer.java:771)

 

Posted
9 minutes ago, diesieben07 said:

...

You need to do it when you are asked for the renderer.

If you don't mind, will you tell me what to do?

 

I can't understand what you are saying, sorry...

Posted

Get the instance of

Minecraft.getInstance().getItemRenderer();

inside IRenderFactory#createRenderFor, and use the returned item renderer in

new RenderSprite<EntityProactiv>

as the item renderer parameter.

Some tips:

Spoiler

Modder Support:

Spoiler

1. Do not follow tutorials on YouTube, especially TechnoVision (previously called Loremaster) and HarryTalks, due to their promotion of bad practice and usage of outdated code.

2. Always post your code.

3. Never copy and paste code. You won't learn anything from doing that.

4. 

Quote

Programming via Eclipse's hotfixes will get you nowhere

5. Learn to use your IDE, especially the debugger.

6.

Quote

The "picture that's worth 1000 words" only works if there's an obvious problem or a freehand red circle around it.

Support & Bug Reports:

Spoiler

1. Read the EAQ before asking for help. Remember to provide the appropriate log(s).

2. Versions below 1.11 are no longer supported due to their age. Update to a modern version of Minecraft to receive support.

 

 

Posted
4 minutes ago, DavidM said:

Get the instance of


Minecraft.getInstance().getItemRenderer();

inside IRenderFactory#createRenderFor, and use the returned item renderer in


new RenderSprite<EntityProactiv>

as the item renderer parameter.

I've solved the problem! Thanks a lot for your help, diesieben07 and DavidM.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
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.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.