Jump to content

[1.12.2] Help with custom entity rendering?


SapphireSky

Recommended Posts

I'm trying to make an item that when thrown creates a pool of fire on impact, yet I'm confused how to get it to actually render.

 

The entity functions as it should, and it renders fine in hand/inventory.

But the entity itself just won't render.

 

I see some people say to register entities from init() and some from preInit() so I tried both, each with negative results.

 

If I call the registry in preInit() as soon as it's thrown and tries to render, the game crashes with a NullPointerException:

Spoiler

net.minecraft.util.ReportedException: Rendering entity in world
	at net.minecraft.client.renderer.entity.RenderManager.renderEntity(RenderManager.java:432) ~[RenderManager.class:?]
	at net.minecraft.client.renderer.entity.RenderManager.renderEntityStatic(RenderManager.java:374) ~[RenderManager.class:?]
	at net.minecraft.client.renderer.RenderGlobal.renderEntities(RenderGlobal.java:655) ~[RenderGlobal.class:?]
	at net.minecraft.client.renderer.EntityRenderer.renderWorldPass(EntityRenderer.java:1400) ~[EntityRenderer.class:?]
	at net.minecraft.client.renderer.EntityRenderer.renderWorld(EntityRenderer.java:1312) ~[EntityRenderer.class:?]
	at net.minecraft.client.renderer.EntityRenderer.updateCameraAndRender(EntityRenderer.java:1115) ~[EntityRenderer.class:?]
	at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:1208) ~[Minecraft.class:?]
	at net.minecraft.client.Minecraft.run(Minecraft.java:441) [Minecraft.class:?]
	at net.minecraft.client.main.Main.main(Main.java:118) [Main.class:?]
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_181]
	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_181]
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_181]
	at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_181]
	at net.minecraft.launchwrapper.Launch.launch(Launch.java:135) [launchwrapper-1.12.jar:?]
	at net.minecraft.launchwrapper.Launch.main(Launch.java:28) [launchwrapper-1.12.jar:?]
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_181]
	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_181]
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_181]
	at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_181]
	at net.minecraftforge.gradle.GradleStartCommon.launch(GradleStartCommon.java:97) [start/:?]
	at GradleStart.main(GradleStart.java:25) [start/:?]
Caused by: java.lang.NullPointerException
	at net.minecraft.client.renderer.entity.RenderSnowball.doRender(RenderSnowball.java:35) ~[RenderSnowball.class:?]
	at net.minecraft.client.renderer.entity.RenderManager.renderEntity(RenderManager.java:390) ~[RenderManager.class:?]
	... 20 more
[21:10:42] [main/INFO] [STDOUT]: [net.minecraft.init.Bootstrap:printToSYSOUT:629]: ---- Minecraft Crash Report ----
// Hi. I'm Minecraft, and I'm a crashaholic.

Time: 3/6/19 9:10 PM
Description: Rendering entity in world

java.lang.NullPointerException: Rendering entity in world
	at net.minecraft.client.renderer.entity.RenderSnowball.doRender(RenderSnowball.java:35)
	at net.minecraft.client.renderer.entity.RenderManager.renderEntity(RenderManager.java:390)
	at net.minecraft.client.renderer.entity.RenderManager.renderEntityStatic(RenderManager.java:374)
	at net.minecraft.client.renderer.RenderGlobal.renderEntities(RenderGlobal.java:655)
	at net.minecraft.client.renderer.EntityRenderer.renderWorldPass(EntityRenderer.java:1400)
	at net.minecraft.client.renderer.EntityRenderer.renderWorld(EntityRenderer.java:1312)
	at net.minecraft.client.renderer.EntityRenderer.updateCameraAndRender(EntityRenderer.java:1115)
	at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:1208)
	at net.minecraft.client.Minecraft.run(Minecraft.java:441)
	at net.minecraft.client.main.Main.main(Main.java:118)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
	at java.lang.reflect.Method.invoke(Unknown Source)
	at net.minecraft.launchwrapper.Launch.launch(Launch.java:135)
	at net.minecraft.launchwrapper.Launch.main(Launch.java:28)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
	at java.lang.reflect.Method.invoke(Unknown Source)
	at net.minecraftforge.gradle.GradleStartCommon.launch(GradleStartCommon.java:97)
	at GradleStart.main(GradleStart.java:25)


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.RenderSnowball.doRender(RenderSnowball.java:35)

-- Entity being rendered --
Details:
	Entity Type: lootboxes:firebomb (avrye.lootboxes.entity.EntityFirebomb)
	Entity ID: 19129
	Entity Name: entity.firebomb.name
	Entity's Exact location: 222.83, 8.55, -463.32
	Entity's Block location: World: (222,8,-464), Chunk: (at 14,0,0 in 13,-29; contains blocks 208,0,-464 to 223,255,-449), Region: (0,-1; contains chunks 0,-32 to 31,-1, blocks 0,0,-512 to 511,255,-1)
	Entity's Momentum: -1.12, -0.99, -0.08
	Entity's Passengers: []
	Entity's Vehicle: ~~ERROR~~ NullPointerException: null

-- Renderer details --
Details:
	Assigned renderer: net.minecraft.client.renderer.entity.RenderSnowball@1b22a77c
	Location: -0.34,1.23,-0.03 - World: (-1,1,-1), Chunk: (at 15,0,15 in -1,-1; contains blocks -16,0,-16 to -1,255,-1), Region: (-1,-1; contains chunks -32,-32 to -1,-1, blocks -512,0,-512 to -1,255,-1)
	Rotation: -94.27165
	Delta: 0.29999375
Stacktrace:
	at net.minecraft.client.renderer.entity.RenderManager.renderEntity(RenderManager.java:390)
	at net.minecraft.client.renderer.entity.RenderManager.renderEntityStatic(RenderManager.java:374)
	at net.minecraft.client.renderer.RenderGlobal.renderEntities(RenderGlobal.java:655)
	at net.minecraft.client.renderer.EntityRenderer.renderWorldPass(EntityRenderer.java:1400)
	at net.minecraft.client.renderer.EntityRenderer.renderWorld(EntityRenderer.java:1312)

-- Affected level --
Details:
	Level name: MpServer
	All players: 1 total; [EntityPlayerSP['Player295'/90, l='MpServer', x=223.96, y=7.99, z=-463.24]]
	Chunk stats: MultiplayerChunkCache: 621, 621
	Level seed: 0
	Level generator: ID 01 - flat, ver 0. Features enabled: false
	Level generator options: 
	Level spawn location: World: (221,4,-553), Chunk: (at 13,0,7 in 13,-35; contains blocks 208,0,-560 to 223,255,-545), Region: (0,-2; contains chunks 0,-64 to 31,-33, blocks 0,0,-1024 to 511,255,-513)
	Level time: 32987 game time, 32987 day time
	Level dimension: 0
	Level storage version: 0x00000 - Unknown?
	Level weather: Rain time: 0 (now: false), thunder time: 0 (now: false)
	Level game mode: Game mode: creative (ID 1). Hardcore: false. Cheats: false
	Forced entities: 10 total; [EntityPig['Pig'/48, l='MpServer', x=177.27, y=4.00, z=-462.62], EntityChicken['Chicken'/32, l='MpServer', x=146.52, y=4.00, z=-504.41], EntityCow['Cow'/49, l='MpServer', x=188.78, y=4.00, z=-448.85], EntityPlayerSP['Player295'/90, l='MpServer', x=223.96, y=7.99, z=-463.24], EntityCow['Cow'/50, l='MpServer', x=197.79, y=4.00, z=-437.62], EntityPig['Pig'/51, l='MpServer', x=211.54, y=4.00, z=-498.40], EntityPig['Pig'/35, l='MpServer', x=149.31, y=4.00, z=-476.41], EntityFirebomb['entity.firebomb.name'/19129, l='MpServer', x=222.83, y=8.55, z=-463.32], EntityPig['Pig'/45, l='MpServer', x=162.69, y=4.00, z=-504.46], EntityPig['Pig'/46, l='MpServer', x=160.24, y=4.00, z=-469.44]]
	Retry entities: 0 total; []
	Server brand: fml,forge
	Server type: Integrated singleplayer server
Stacktrace:
	at net.minecraft.client.multiplayer.WorldClient.addWorldInfoToCrashReport(WorldClient.java:461)
	at net.minecraft.client.Minecraft.addGraphicsAndWorldToCrashReport(Minecraft.java:2888)
	at net.minecraft.client.Minecraft.run(Minecraft.java:462)
	at net.minecraft.client.main.Main.main(Main.java:118)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
	at java.lang.reflect.Method.invoke(Unknown Source)
	at net.minecraft.launchwrapper.Launch.launch(Launch.java:135)
	at net.minecraft.launchwrapper.Launch.main(Launch.java:28)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
	at java.lang.reflect.Method.invoke(Unknown Source)
	at net.minecraftforge.gradle.GradleStartCommon.launch(GradleStartCommon.java:97)
	at GradleStart.main(GradleStart.java:25)

 

 

 

But if I call the registry in init() instead of crashing, everything works perfectly except that it renders as just a small white cube.

 

 

Any help?

 

Entities:

Spoiler

public class Entities
{
	public static int entityId = 0;

	public static final EntityEntry firebomb = newEntry("firebomb", EntityFirebomb.class);

	public static <E extends Entity> EntityEntry newEntry(String name, Class<? extends E> entity)
	{
		return EntityEntryBuilder.create().entity(entity).id(new ResourceLocation(Main.MODID, name), entityId++).name(name)
				.tracker(64, 5, true).build();
	}
}

 

 

Registry:

Spoiler

@EventBusSubscriber
public class Registry
{
	// item list
	// block list
	// item registry event
	// block registry event
	// itemblock registry event
	// model registry event

	@SubscribeEvent
	public static void register(Register<EntityEntry> event)
	{
		event.getRegistry().register(Entities.firebomb);
	}

        // This is called from ClientProxy
	public static void render()
	{
		RenderItem renderItem = Minecraft.getMinecraft().getRenderItem();
		RenderManager renderManager = Minecraft.getMinecraft().getRenderManager();

		RenderingRegistry.registerEntityRenderingHandler(EntityFirebomb.class, new IRenderFactory<EntityFirebomb>()
		{
			@Override
			public Render<? super EntityFirebomb> createRenderFor(RenderManager manager)
			{
				return new RenderSnowball<EntityFirebomb>(renderManager, claybomb, renderItem);
			}
		});
	}
}

 

 

EntityFirebomb:

Spoiler

public class EntityFirebomb extends EntityThrowable
{
	private int radius, entityDamage;

	public EntityFirebomb(World world)
	{
		super(world);
	}

	public EntityFirebomb(World world, EntityLivingBase thrower, int radius, int entityDamage)
	{
		super(world, thrower);
		this.radius = radius;
		this.entityDamage = entityDamage;
	}

	public EntityFirebomb(World world, double x, double y, double z, int radius, int entityDamage)
	{
		super(world, x, y, z);
		this.radius = radius;
		this.entityDamage = entityDamage;
	}

	@Override
	protected void onImpact(RayTraceResult result)
	{
		ArrayList<BlockPos> affectedBlocks = new ArrayList<BlockPos>();
		BlockPos pos = null;

		if (result.typeOfHit == RayTraceResult.Type.BLOCK)
		{
			if (result.getBlockPos() == null || result.getBlockPos() == BlockPos.ORIGIN)
			{
				pos = this.getPosition();
			}
			else
			{
				pos = result.getBlockPos();
			}
		}
		else if (result.typeOfHit == RayTraceResult.Type.ENTITY)
		{
			if (result.entityHit != null)
			{
				result.entityHit.attackEntityFrom(DamageSource.causeThrownDamage(this, this.getThrower()), entityDamage);

				pos = result.entityHit.getPosition();
			}
		}

		if (pos == null || world.getBlockState(pos).getMaterial() == Material.WATER)
		{
			return;
		}

		for (int i = -radius; i < radius; i++)
		{
			for (int j = -radius; j < radius; j++)
			{
				for (int k = -radius; k < radius; k++)
				{
					affectedBlocks.add(new BlockPos(pos.getX() + i, pos.getY() + j, pos.getZ() + k));
				}
			}
		}

		Random r = new Random();
		for (BlockPos b : affectedBlocks)
		{
			if (this.world.getBlockState(b).getMaterial() == Material.AIR && this.world.getBlockState(b.down()).isFullBlock()
					&& r.nextInt(3) == 0)
			{
				this.world.setBlockState(b, Blocks.FIRE.getDefaultState());
			}
		}
		world.playSound((EntityPlayer) null, this.posX, this.posY, this.posZ, SoundEvents.BLOCK_GLASS_BREAK, SoundCategory.PLAYERS, 0.5F,
				0.6f);

		if (!this.world.isRemote)
		{
			this.world.setEntityState(this, (byte) 3);
			this.setDead();
		}
	}
}

 

 

 

Link to comment
Share on other sites

Please read https://gist.github.com/Cadiboo/fbea89dc95ebbdc58d118f5350b7ba93. Get rid of all of this

// This is called from ClientProxy
	public static void render()
	{
		RenderItem renderItem = Minecraft.getMinecraft().getRenderItem();
		RenderManager renderManager = Minecraft.getMinecraft().getRenderManager();

		RenderingRegistry.registerEntityRenderingHandler(EntityFirebomb.class, new IRenderFactory<EntityFirebomb>()
		{
			@Override
			public Render<? super EntityFirebomb> createRenderFor(RenderManager manager)
			{
				return new RenderSnowball<EntityFirebomb>(renderManager, claybomb, renderItem);
			}
		});
	}

and replace it with something that isn't broken. You're passed a RenderManager in from createRenderFor why do you use the other one. Why does the other one even exist? Heres an example of how to register a renderer https://github.com/Cadiboo/WIPTech/blob/fb5883e9d76ef0361ec1ebbcb9c508611dd2ef6b/src/main/java/cadiboo/wiptech/client/ClientEventSubscriber.java#L137 

About Me

Spoiler

My Discord - Cadiboo#8887

My WebsiteCadiboo.github.io

My ModsCadiboo.github.io/projects

My TutorialsCadiboo.github.io/tutorials

Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support.

When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible.

Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org

Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)

Link to comment
Share on other sites

7 minutes ago, Cadiboo said:

Please read https://gist.github.com/Cadiboo/fbea89dc95ebbdc58d118f5350b7ba93. Get rid of all of this


// This is called from ClientProxy
	public static void render()
	{
		RenderItem renderItem = Minecraft.getMinecraft().getRenderItem();
		RenderManager renderManager = Minecraft.getMinecraft().getRenderManager();

		RenderingRegistry.registerEntityRenderingHandler(EntityFirebomb.class, new IRenderFactory<EntityFirebomb>()
		{
			@Override
			public Render<? super EntityFirebomb> createRenderFor(RenderManager manager)
			{
				return new RenderSnowball<EntityFirebomb>(renderManager, claybomb, renderItem);
			}
		});
	}

and replace it with something that isn't broken. You're passed a RenderManager in from createRenderFor why do you use the other one. Why does the other one even exist? Heres an example of how to register a renderer https://github.com/Cadiboo/WIPTech/blob/fb5883e9d76ef0361ec1ebbcb9c508611dd2ef6b/src/main/java/cadiboo/wiptech/client/ClientEventSubscriber.java#L137 

The RenderManager was only there because of something else I was trying that didn't work; forgot to remove it.

 

Also, changing it to this...

Spoiler

public static void render()
{
	//....
  
	RenderingRegistry.registerEntityRenderingHandler(EntityFirebomb.class, RenderFirebomb::new);
}

@SideOnly(Side.CLIENT)
public class RenderFirebomb extends Render<EntityFirebomb>
{
	protected final Item item;
	private final RenderItem itemRenderer;

	public RenderFirebomb(final RenderManager renderManager)
	{
		super(renderManager);
		this.item = Registry.claybomb;
		this.itemRenderer = Minecraft.getMinecraft().getRenderItem();
	}

	@Override
	public void doRender(EntityFirebomb entity, double x, double y, double z, float entityYaw, float partialTicks)
	{
		GlStateManager.pushMatrix();
		GlStateManager.translate((float) x, (float) y, (float) z);
		GlStateManager.enableRescaleNormal();
		GlStateManager.rotate(-this.renderManager.playerViewY, 0.0F, 1.0F, 0.0F);
		GlStateManager.rotate((float) (this.renderManager.options.thirdPersonView == 2 ? -1 : 1) * this.renderManager.playerViewX, 1.0F,
				0.0F, 0.0F);
		GlStateManager.rotate(180.0F, 0.0F, 1.0F, 0.0F);
		this.bindTexture(TextureMap.LOCATION_BLOCKS_TEXTURE);

		if (this.renderOutlines)
		{
			GlStateManager.enableColorMaterial();
			GlStateManager.enableOutlineMode(this.getTeamColor(entity));
		}

		this.itemRenderer.renderItem(new ItemStack(this.item), ItemCameraTransforms.TransformType.GROUND);

		if (this.renderOutlines)
		{
			GlStateManager.disableOutlineMode();
			GlStateManager.disableColorMaterial();
		}

		GlStateManager.disableRescaleNormal();
		GlStateManager.popMatrix();
		super.doRender(entity, x, y, z, entityYaw, partialTicks);
	}

	protected ResourceLocation getEntityTexture(EntityFirebomb entity)
	{
		return TextureMap.LOCATION_BLOCKS_TEXTURE;
	}
}

 

still produces the same result. Renders a white cube instead of the item. Did I miss something?

Link to comment
Share on other sites

Unless you're trying to render a white cube, it means that your renderer isn't getting registered properly. Please post your code as a working GitHub repository.

About Me

Spoiler

My Discord - Cadiboo#8887

My WebsiteCadiboo.github.io

My ModsCadiboo.github.io/projects

My TutorialsCadiboo.github.io/tutorials

Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support.

When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible.

Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org

Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)

Link to comment
Share on other sites

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.