Jump to content
  • Home
  • Files
  • Docs
Topics
  • All Content

  • This Topic
  • This Forum

  • Advanced Search
  • Existing user? Sign In  

    Sign In



    • Not recommended on shared computers


    • Forgot your password?

  • Sign Up
  • All Activity
  • Home
  • Mod Developer Central
  • Modder Support
  • [SOLVED] Throwable Item Rendering in 1.16.1
Currently Supported: 1.16.X (Latest) and 1.15.X (LTS)
Sign in to follow this  
Followers 2
Codex79

[SOLVED] Throwable Item Rendering in 1.16.1

By Codex79, November 26, 2020 in Modder Support

  • Reply to this topic
  • Start new topic

Recommended Posts

Codex79    0

Codex79

Codex79    0

  • Tree Puncher
  • Codex79
  • Members
  • 0
  • 4 posts
Posted November 26, 2020 (edited)

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 November 27, 2020 by Codex79
The problem is fixed.
  • Quote

Share this post


Link to post
Share on other sites

TheGreyGhost    819

TheGreyGhost

TheGreyGhost    819

  • Reality Controller
  • TheGreyGhost
  • Members
  • 819
  • 3280 posts
Posted November 26, 2020

Howdy

 

You'll probably find this working tutorial example helpful

https://github.com/TheGreyGhost/MinecraftByExample/tree/master/src/main/java/minecraftbyexample/mbe81_entity_projectile

 

mbe81a.png

 

-TGG

  • Quote

Share this post


Link to post
Share on other sites

Beethoven92    69

Beethoven92

Beethoven92    69

  • Dragon Slayer
  • Beethoven92
  • Members
  • 69
  • 556 posts
Posted November 26, 2020 (edited)

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 November 26, 2020 by Beethoven92
  • Haha 1
  • Quote

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

A little fun project: https://www.curseforge.com/minecraft/mc-mods/two-players-one-horse

Share this post


Link to post
Share on other sites

Codex79    0

Codex79

Codex79    0

  • Tree Puncher
  • Codex79
  • Members
  • 0
  • 4 posts
Posted November 26, 2020 (edited)

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 November 26, 2020 by Codex79
  • Quote

Share this post


Link to post
Share on other sites

Beethoven92    69

Beethoven92

Beethoven92    69

  • Dragon Slayer
  • Beethoven92
  • Members
  • 69
  • 556 posts
Posted November 26, 2020

Usually logs will tell you where the null pointer exception was thrown at, reading them may be useful. Also please, show your entire code, in particular your custom entity class

  • Quote

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

A little fun project: https://www.curseforge.com/minecraft/mc-mods/two-players-one-horse

Share this post


Link to post
Share on other sites

ChampionAsh5357    160

ChampionAsh5357

ChampionAsh5357    160

  • World Shaper
  • ChampionAsh5357
  • Members
  • 160
  • 1019 posts
Posted November 26, 2020
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.

  • Quote

Share this post


Link to post
Share on other sites

Codex79    0

Codex79

Codex79    0

  • Tree Puncher
  • Codex79
  • Members
  • 0
  • 4 posts
Posted November 26, 2020 (edited)
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 November 26, 2020 by Codex79
  • Quote

Share this post


Link to post
Share on other sites

Beethoven92    69

Beethoven92

Beethoven92    69

  • Dragon Slayer
  • Beethoven92
  • Members
  • 69
  • 556 posts
Posted November 26, 2020
@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
  • Quote

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

A little fun project: https://www.curseforge.com/minecraft/mc-mods/two-players-one-horse

Share this post


Link to post
Share on other sites

Codex79    0

Codex79

Codex79    0

  • Tree Puncher
  • Codex79
  • Members
  • 0
  • 4 posts
Posted November 26, 2020
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.

  • Quote

Share this post


Link to post
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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  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.

    • Insert image from URL
×
  • Desktop
  • Tablet
  • Phone
Sign in to follow this  
Followers 2
Go To Topic Listing



  • Recently Browsing

    No registered users viewing this page.

  • Posts

    • TheDonkey_King
      I just started modding minecraft and I thought i had finished modding it but Titanium mod isn't loading properly. Can someone help me fix this?

      By TheDonkey_King · Posted 7 minutes ago

      What file?
    • BIGDog8808
      HELP! WORLD WONT WORK

      By BIGDog8808 · Posted 9 minutes ago

      so is there anyway that i can copy the world and use it with forge  
    • mightymoy
      Cant craft items in modded server

      By mightymoy · Posted 16 minutes ago

      we arent using Opti fine anymore and no specific reason we had just picked 1.16.1 
    • DaemonUmbra
      Cant craft items in modded server

      By DaemonUmbra · Posted 20 minutes ago

      Well first of all you have Optifine on a server, which is pointless and only adds a possible point of failure. Second, why are you using 1.16.1?
    • DaemonUmbra
      HELP! WORLD WONT WORK

      By DaemonUmbra · Posted 23 minutes ago

      Ok so in modern versions of Forge, server configs are save-specific, and your server config has become corrupted, delete it
  • Topics

    • TheDonkey_King
      4
      I just started modding minecraft and I thought i had finished modding it but Titanium mod isn't loading properly. Can someone help me fix this?

      By TheDonkey_King
      Started 5 hours ago

    • BIGDog8808
      10
      HELP! WORLD WONT WORK

      By BIGDog8808
      Started 6 hours ago

    • mightymoy
      8
      Cant craft items in modded server

      By mightymoy
      Started Yesterday at 03:00 AM

    • tinyborisYT
      2
      [1.12.2] Crash at Launch, No clue why

      By tinyborisYT
      Started 1 hour ago

    • TurtlesAreHot
      3
      [1.16.4] License Issue..

      By TurtlesAreHot
      Started 3 hours ago

  • Who's Online (See full list)

    • Caffeinated Pinkie
    • AntiRix
    • TheDonkey_King
    • Umpaz
    • Woodside
    • BIGDog8808
    • Eldritas-Nacht
    • mightymoy
    • DaemonUmbra
  • All Activity
  • Home
  • Mod Developer Central
  • Modder Support
  • [SOLVED] Throwable Item Rendering in 1.16.1
  • Theme

Copyright © 2019 ForgeDevelopment LLC · Ads by Longitude Ads LLC Powered by Invision Community