Jump to content

[SOLVED] Throwable Item Rendering in 1.16.1


Codex79

Recommended Posts

I am trying to develop a mod for 1.16.1, and I am having trouble rending a throwable item when it is in flight. My main problem is that most other tutorials or suggestions use RendererSnowball (or Snowball Renderer, I can't remember) which doesn't seem to exist for versions after 1.15. So is there an adequate subsuite that could help me? For reference this is my ClientEventBusSubscriber class: 

package com.codex.cottage_craft.util;

import...

@Mod.EventBusSubscriber(value=Dist.CLIENT,modid= CottageCraft.MOD_ID)
public class ClientEventBusSubscriber {

	/* -main methods- */
	/** A method that registers the models through a model registry event.
	 * 		@param	event	The model registry event that registers the models of entities and blocks. */
	@SubscribeEvent
    public static void onRegisterModelsEvent(ModelRegistryEvent event) {
        registerEntityRenderers();
    }
	
	
	/* -helper methods- */
	/** A helper method that targets rendering entity models specifically. */
	private static void registerEntityRenderers() {
    	
		// registers the silver pearl entity with the rendering factory that returns a sprite render.
    	RenderingRegistry.registerEntityRenderingHandler(
    			EntityCollection.SILVER_ENDER_PEARL_ENTITY.get(),
    			new IRenderFactory<SilverEnderPearlEntity> () {
					public EntityRenderer<? super SilverEnderPearlEntity> createRenderFor(EntityRendererManager manager) {
						return new SpriteRenderer<SilverEnderPearlEntity> (manager, Minecraft.getInstance().getItemRenderer());
                    }
                }
        );

    }
	
}

I was hoping to replace the "SpriteRenderer<SilverEnderPearlEntity>" with a SnowballRenderer or RendererSnowball. Any help would be appreciated, including the way Snowball and Ender Pearls are now rendered. Also, the error that is actually occurring for me is a Null Pointer error but even if I were to resolve it I don't think it would work.

Edited by Codex79
The problem is fixed.
Link to comment
Share on other sites

Snowballs, ender pearls, eggs, eyes of ender...are all rendered through the SpriteRenderer..you may want to explore a bit that class and also you may find this example very useful: https://github.com/TheGreyGhost/MinecraftByExample/tree/1-16-3-final/src/main/java/minecraftbyexample/mbe81_entity_projectile

 

Edit: wooops, sorry TheGreyGhost, you were 1 second faster than me

Edited by Beethoven92
  • Haha 1

Check out the port of the BetterEnd fabric mod (WIP): https://www.curseforge.com/minecraft/mc-mods/betterend-forge-port

Link to comment
Share on other sites

Thank you both. Unfortunately, I keep getting a null pointer exception whenever I throw the ender pearl and cannot for the life of me figure out why. But I think I'm just going to use EntityType.ENDER_PEARL instead of the one I made.

 

EDIT: Also I did check out the GitHub and I'm pretty sure I'm doing everything right for the registerEntityRenderingHandler. I think the exception exists in my EntityCollection where I build the entity type, but as I said before I think I'm going to forgo using a custom entity type. 

Edited by Codex79
Link to comment
Share on other sites

54 minutes ago, Codex79 said:

but as I said before I think I'm going to forgo using a custom entity type. 

To create a custom entity, it needs to be specified with a custom type. Otherwise, vanilla packets will take a semi-precedent when synchronizing data which can be problematic in a lot of cases. In the case of a projectile entity, it only needs the attached renderer and the registry entry.

Link to comment
Share on other sites

1 hour ago, Beethoven92 said:

Usually logs will tell you where the null pointer exception was thrown at, reading them may be useful.

I have been reading the logs; however, they only tell me where the null pointer exception occurs in the forge referenced libraries and not in my actual code so I'm at a loss. It seems to have to do with the Minecraft.getInstance().getRenderingManager() but I'm not sure if that is null or just using an associated null object. I've been trying to debug my code to no avail. Here's the relevant crash report: 

---- Minecraft Crash Report ----
// I blame Dinnerbone.

Time: 11/26/20 4:38 PM
Description: Unexpected error

java.lang.NullPointerException: Unexpected error
	at net.minecraft.client.renderer.entity.EntityRendererManager.shouldRender(EntityRendererManager.java:238) ~[forge-1.16.1-32.0.108_mapped_snapshot_20200514-1.16-recomp.jar:?] {re:classloading,pl:accesstransformer:B,pl:runtimedistcleaner:A}
	at net.minecraft.client.renderer.WorldRenderer.updateCameraAndRender(WorldRenderer.java:983) ~[forge-1.16.1-32.0.108_mapped_snapshot_20200514-1.16-recomp.jar:?] {re:classloading,pl:runtimedistcleaner:A}
	at net.minecraft.client.renderer.GameRenderer.renderWorld(GameRenderer.java:613) ~[forge-1.16.1-32.0.108_mapped_snapshot_20200514-1.16-recomp.jar:?] {re:classloading,pl:accesstransformer:B,pl:runtimedistcleaner:A}
	at net.minecraft.client.renderer.GameRenderer.updateCameraAndRender(GameRenderer.java:434) ~[forge-1.16.1-32.0.108_mapped_snapshot_20200514-1.16-recomp.jar:?] {re:classloading,pl:accesstransformer:B,pl:runtimedistcleaner:A}
	at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:988) ~[forge-1.16.1-32.0.108_mapped_snapshot_20200514-1.16-recomp.jar:?] {re:classloading,pl:accesstransformer:B,pl:runtimedistcleaner:A}
	at net.minecraft.client.Minecraft.run(Minecraft.java:587) ~[forge-1.16.1-32.0.108_mapped_snapshot_20200514-1.16-recomp.jar:?] {re:classloading,pl:accesstransformer:B,pl:runtimedistcleaner:A}
	at net.minecraft.client.main.Main.main(Main.java:184) ~[forge-1.16.1-32.0.108_mapped_snapshot_20200514-1.16-recomp.jar:?] {re:classloading,pl:runtimedistcleaner:A}
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_121] {}
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_121] {}
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_121] {}
	at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_121] {}
	at net.minecraftforge.userdev.FMLUserdevClientLaunchProvider.lambda$launchService$0(FMLUserdevClientLaunchProvider.java:55) ~[forge-1.16.1-32.0.108_mapped_snapshot_20200514-1.16-recomp.jar:?] {}
	at cpw.mods.modlauncher.LaunchServiceHandlerDecorator.launch(LaunchServiceHandlerDecorator.java:37) [modlauncher-6.1.3.jar:?] {}
	at cpw.mods.modlauncher.LaunchServiceHandler.launch(LaunchServiceHandler.java:54) [modlauncher-6.1.3.jar:?] {}
	at cpw.mods.modlauncher.LaunchServiceHandler.launch(LaunchServiceHandler.java:72) [modlauncher-6.1.3.jar:?] {}
	at cpw.mods.modlauncher.Launcher.run(Launcher.java:81) [modlauncher-6.1.3.jar:?] {}
	at cpw.mods.modlauncher.Launcher.main(Launcher.java:65) [modlauncher-6.1.3.jar:?] {}
	at net.minecraftforge.userdev.LaunchTesting.main(LaunchTesting.java:105) [forge-1.16.1-32.0.108_mapped_snapshot_20200514-1.16-recomp.jar:?] {}


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

-- Head --
Thread: Render thread
Stacktrace:
	at net.minecraft.client.renderer.entity.EntityRendererManager.shouldRender(EntityRendererManager.java:238)
	at net.minecraft.client.renderer.WorldRenderer.updateCameraAndRender(WorldRenderer.java:983)
	at net.minecraft.client.renderer.GameRenderer.renderWorld(GameRenderer.java:613)

And here is my custom entity class: 

public class SilverEnderPearlEntity extends ProjectileItemEntity {

	/* -constructors- */
	/** An initialization constructor that overrides a constructor in EnderPearlEntity.
	 * 		@param	worldIn		The current world that is loaded.
	 * 		@param	throwerIn	The entity doing the throwing, e.g., a player. */
	public SilverEnderPearlEntity(World worldIn, LivingEntity throwerIn) {
		super(/*EntityType.ENDER_PEARL*/EntityCollection.SILVER_ENDER_PEARL_ENTITY.get(), throwerIn, worldIn);}
	
	/** Another initialization constructor that overrides a constructor in EnderPearlEntity.
	 * 		@param	entityType	The type of entity throwing the ender pearl.
	 * 		@param	worldIn		The current world that is loaded. */
	public SilverEnderPearlEntity(EntityType<? extends ProjectileItemEntity> entityType, World worldIn) {
		super(entityType, worldIn);}
	
	/** Another initialization constructor that overrides a constructor in EnderPearlEntity.
	 * 		@param	worldIn	The current world that is loaded.
	 *		@param	x		The x position that the entity (and player) will be sent to.
	 *		@param	y		The y position that the entity (and player) will be sent to.
	 *		@param	z		The z position that the entity (and player) will be sent to. */
	@OnlyIn(Dist.CLIENT)
	public SilverEnderPearlEntity(World worldIn, double x, double y, double z) {
		super(/*EntityType.ENDER_PEARL*/EntityCollection.SILVER_ENDER_PEARL_ENTITY.get(), x, y, z, worldIn);}
	
	
	/* -entity rendering methods- */
	/** A method that returns the spawn packet required to be overridden by custom entity classes. 
	 * 		@return	A spawn packet used by throwable entities. */
	public IPacket<?> createSpawnPacket() {
		   return NetworkHooks.getEntitySpawningPacket(this);}
	
	/** A method that returns the default item that uses this entity, i.e., the silver ender pearl. 
	 * 		@return	The default item that uses this entity. */
	protected Item getDefaultItem() {
		return /*Items.ENDER_PEARL;*/EndTab.SILVER_ENDER_PEARL.get();}
	
	
	/* -important overridden methods- */
	/** Called whenever the silver ender pearl hits only an entity.
	 * 		@param	result	The path of the ray tracing result. */
	protected void onEntityHit(EntityRayTraceResult result) {
	      super.onEntityHit(result);
	      result.getEntity().attackEntityFrom(DamageSource.causeThrownDamage(this, this.func_234616_v_()), 0.0F);}
	
	/** Called whenever the silver ender pearl hits an entity or block.
	 * 		@param	result	The resulting path that is given by throwing the ender pearl. */
	@SuppressWarnings("deprecation")
	protected void onImpact(RayTraceResult result) {
		
		// gets the entity that activated the silver ender pearl.
		super.onImpact(result);
		Entity entity = this.func_234616_v_();

		// if the world is not remote and the ender pearl entity has not been removed yet.
		if(!this.world.isRemote && !this.removed) {
			
			// if the entity is a server player entity.
			if(entity instanceof ServerPlayerEntity) {
				ServerPlayerEntity serverPlayerEntity = (ServerPlayerEntity) entity;
				if(serverPlayerEntity.connection.getNetworkManager().isChannelOpen() && serverPlayerEntity.world == this.world && !serverPlayerEntity.isSleeping()) {
					
					// creates the teleport event.
					EnderTeleportEvent event = new EnderTeleportEvent(
							serverPlayerEntity, this.getPosX(),
							this.getPosY(), this.getPosZ(), 2.5f);
					if(!net.minecraftforge.common.MinecraftForge.EVENT_BUS.post(event)) {
						
						// spawns a random mob if the player is unlucky.
						if(this.rand.nextFloat() < 0.05F && this.world.getGameRules().getBoolean(GameRules.DO_MOB_SPAWNING)) {
							
							EndermiteEntity endermiteEntity = EntityType.ENDERMITE.create(this.world);
							endermiteEntity.setSpawnedByPlayer(true);
							endermiteEntity.setLocationAndAngles(entity.getPosX(), entity.getPosY(), entity.getPosZ(), entity.rotationYaw, entity.rotationPitch);
							
							this.world.addEntity(endermiteEntity);}
	
						// if their is a passenger, the passenger will stop riding.
						if (entity.isPassenger())
							entity.stopRiding();
	
						// set the new position of the player.
						entity.setPositionAndUpdate(event.getTargetX(), event.getTargetY(), event.getTargetZ());
						entity.fallDistance = 0.0F;
						entity.attackEntityFrom(DamageSource.FALL, event.getAttackDamage());}}}
			
			// if the entity is something other than a player.
			else if (entity != null) {
				entity.setPositionAndUpdate(this.getPosX(), this.getPosY(), this.getPosZ());
				entity.fallDistance = 0.0F;}

			// remove this silver ender pearl entity.
			this.remove();}}
	
	
	/* -other overridden methods- */
	/** Called to update properties of the entity. */
	public void tick() {
		
		Entity entity = this.func_234616_v_();
		
		if (entity instanceof PlayerEntity && !entity.isAlive()) 
			this.remove();
		else 
			super.tick();}

	/** A method that changes the dimension if the ender pearl is thrown into an end gate way or
	 *	something to that effect.
	 *		@param	serverWorldIn	The current server world that is loaded in.
	 *		@param	teleporter		An object that handles positioning during a dimension change.
	 *		@return	An entity in a differing dimension. */
	public Entity changeDimension(ServerWorld serverWorldIn, net.minecraftforge.common.util.ITeleporter teleporter) {
		
		Entity entity = this.func_234616_v_();
		if (entity != null && entity.world.func_234923_W_() != serverWorldIn.func_234923_W_())
			this.setShooter((Entity)null);

		return super.changeDimension(serverWorldIn, teleporter);}
	
}

And where I initialize the entity type:

public class EntityCollection {

	/* -entity registry objects- */
	/** A registry object for our silver ender pearl entities. */
	public static RegistryObject< EntityType<SilverEnderPearlEntity> > SILVER_ENDER_PEARL_ENTITY;
	
	
	/* -static method initialization- */
	/** A method that acts like a constructor to initialize our static instance objects and add
	 * 	them to the registry. */
	public static void init() {
		
		SILVER_ENDER_PEARL_ENTITY = EntityRegistryHandler.ENTITIES.register("silver_ender_pearl", 
				() -> EntityType.Builder.<SilverEnderPearlEntity>create(
						SilverEnderPearlEntity::new, EntityClassification.MISC)
				.size(0.25f, 0.25f).func_233606_a_(4).func_233608_b_(10)
				.build(new ResourceLocation(CottageCraft.MOD_ID, "silver_ender_pearl").toString()));}
	
}

 

1 hour ago, ChampionAsh5357 said:

To create a custom entity, it needs to be specified with a custom type. Otherwise, vanilla packets will take a semi-precedent when synchronizing data which can be problematic in a lot of cases.

Thank you. I'll keep that in mind since I had no idea and thought using EntityType.ENDER_PEARL would be appropriate if I or someone else didn't come up with a solution.

Edited by Codex79
Link to comment
Share on other sites

@Mod.EventBusSubscriber(value=Dist.CLIENT,modid= CottageCraft.MOD_ID)

You are registering your event handler to the wrong bus, so your registerEntityRenderers() is never executed. Remember that when no bus is specified, default goes to the forge bus. ModelRegistryEvent is fired on the mod bus

  • Thanks 1

Check out the port of the BetterEnd fabric mod (WIP): https://www.curseforge.com/minecraft/mc-mods/betterend-forge-port

Link to comment
Share on other sites

44 minutes ago, Beethoven92 said:

@Mod.EventBusSubscriber(value=Dist.CLIENT,modid= CottageCraft.MOD_ID)

You are registering your event handler to the wrong bus, so your registerEntityRenderers() is never executed. Remember that when no bus is specified, default goes to the forge bus. ModelRegistryEvent is fired on the mod bus

Thank you so much! I added a bus = Mod.EventBusSubscriber.Bus.MOD in the parentheses and that fixed it.

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.



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • I've had this problem for a long while now, and am just now remembering that Forge has a forum site. I feel dumb that I could've had this problem solved sooner. Though it is a problem I've only experienced as of 1.20(to my memory). Everything prior to that version worked fine up until I installed Forge 1.20. Anyway, I've tried some things including trying previous versions and (at the recommendation of others)taking my resource pack off. Paste.ee link lol Running Minecraft version 1.12 is the version of Forge that works without issues. I've deduced that this is because the overlay that loads the game and mods in future versions of Forge is not present, but this still doesn't solve my problem of how to fix the crashing of said future versions, or why it crashes in the first place. Yes, this happens even without mods. I'm not very good at messing with files, so here I am. Hopefully I did this right after looking at the FAQ.
    • it seems i can put back my mods in my mods folder one by one with their dependencies to get the config file, but when i put 2 or more it doesn't create it
    • Call+27732318372 $100‱-Authentic-Love Spells New York-London-Tokyo-Sydney-Toronto Visit website: https://www.strongspellcaster.us.com. For Rebinding Love Spells New York, Best love spells New York, Genuine love spells New York, Attraction love spells New York, Marriage spells New York, Divorce spells New York, Stop Cheating spells New York, Return Ex-Lover New York, Real Love spells New York, Bring back Ex Lover and Psychic Reader in USA. +27732318372 Are you currently seeing someone? Are you feeling that your lover’s love for is slowly diminishing? Are you looking for something that will instantly strengthen your relationship? Have you tried seeking help from various spell casters but failed because they only gave false hope? Are you hoping to win your lost lover back? Is your current relationship giving you so much misery? Do you want the man/girl of your dreams to find you alluring? Then you are at the right place because here you will find exactly what you have been searching for and that is the Return of Your Lost Love My name is Aadila. During the last 30 years, I have helped many people solve their relationship problems and financial difficulties with powerful Egyptian magic spells. All my clients had different problems, wishes, and goals. All situations involved various people, different spirits, and different souls and as the name goes I am truly a Lovespell Expert. Therefore it is very important that I get to know you, and your problem and gain profound insight into your situation. All my spell work is tailored to your specific needs because this is the only way you will receive your results, and your problems will be solved in a timely manner. You contacted me because you have a problem in your life, which you would like to solve through authentic spiritual means. I am here to assist you. While browsing my site, you will get to know me better, and this site will prepare you to make the right decision. website: https://www.strongspellcaster.us.com. Vodoo is an oral tradition practised by extended families that inherit familial spirits, along with the necessary devotional practices, from their elders. In the cities, local hierarchies of priestesses or priests (manbo and oungan), “children of the spirits” (ounsi), and ritual drummers (ountògi) comprise more formal “societies” or “congregations” (sosyete). In these congregations, knowledge is passed on through a ritual of initiation (kanzo) in which the body becomes the site of spiritual transformation. There is some regional difference in ritual practice across Haiti, and branches of the religion include Rada, Daome, Ibo, Nago, Dereal, Manding, Petwo, and Kongo. There is no centralized hierarchy, no single leader, and no official spokesperson, but various groups sometimes attempt to create such official structures. There are also secret societies, called Bizango or Sanpwèl, that perform a religio-juridical function. I have been having lots of questions from clients about our prices, As a voodoo Priest, it’s 100% forbidden to tax anyone for our services (It's a Taboo). We will only accept FREE WILL DONATIONS AFTER YOU HAVE SEEN RESULTS and not forgetting that every ritual has a list of items to use so all customers PROVIDE JUST THEIR ITEMS NEEDED FOR THEIR WORK Depending on their request!
    • Call +27732318372 $100‱ -Lottery Spells USA: Most Powerful Lottery Spells to Win the Mega Millions in New York. Visit website: https://www.strongspellcaster.us.com I'm William Jones  from the United States. I started playing lottery games 4 years ago and I have never won big. I went online to seek help on how I can win big in my lottery games and I saw some nice reviews about Prof Mama Khulusum who has made different people huge winners in their lottery games with her prayers. I gave it a try and I contacted Prof Mama Khulusum who told me how and what to do before I can become a big lotto winner and I accepted. 
    • $100‱+27732318372 NEW YORK-## LOTTERY SPELLS #STAR# LOTTERY SPELLS THAT NEVER MISS IN USA. visit also my website: https://www.strongspellcaster.us.com HOW TO WIN LOTTERY JACKPOT ASK DR MAMA KHULUSUM IN Fiji Island, Malta, Greek Island cruise, Amelia Island properties, Robin Island, Channel Island By a real lottery spell cater prof mama KHULUSUM +27732318372. Who doesn’t want to win the lottery? Chances are that most of us could do with a little
  • Topics

  • Who's Online (See full list)

    • There are no registered users currently online
×
×
  • Create New...

Important Information

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