Jump to content

Registering and rendering


American2050

Recommended Posts

I have a question, I notice this happens for entities but not for items/blocks

 

I have a class for example named "ModItems" and in there I have 2 methods, one for registering the items (called from the mod main class) and other for registering the renders (called from the client proxy) So far so good.

Problem is, when I do the same for TileEntities, when I try to launch server it complains that I'm calling the register of renders for entities from the server side. Even when that's not actually happening.

 

java.lang.NoClassDefFoundError: net/minecraft/client/renderer/tileentity/TileEntitySpecialRenderer
	at com.mramericanmike.irishluck.IrishLuck.preInit(IrishLuck.java:88) ~[bin/:?]

 

That line actually is

    	ModTE.init();

 

And ModTE is
 

public class ModTE {
	
	public static void init() {
		GameRegistry.registerTileEntity(TEBlockError404.class, "block_irishluck_big_404");
		GameRegistry.registerTileEntity(TEBlockGhost.class, "block_ghost");
	}

	
	public static void registerRenders() {
		TileEntitySpecialRenderer renderBE404 = new RenderBlockError404();
		ClientRegistry.bindTileEntitySpecialRenderer(TEBlockError404.class, renderBE404);
		
	}
}

 

And... Probably here is my problem, as I write it I notice this, I'm calling that regsterRenders from ClientProxy preInit

	public void preInit()
	{
		//Register Renders on Client Side Only
		ModItems.registerRenders();
		ModBlocks.registerRenders();
		
		ModTE.registerRenders();
		      
	}

 

What could be causing this behavior?

 

Thanks a lot.

 

 

PS: As I write this and compare with my other classes I notice I was missing the

@SideOnly(Side.CLIENT)

 

But I'm confuse... If the method isn't getting called, why it executes it anyway? And... Weren't we supposed to not use @SideOnly(Side.CLIENT) anymore?

Once again, thanks for any clarification about this ;)

Link to comment
Share on other sites

24 minutes ago, American2050 said:

But I'm confuse... If the method isn't getting called, why it executes it anyway? And... Weren't we supposed to not use @SideOnly(Side.CLIENT) anymore?

It's not that the method is being executed. It's just that Java (tries to) load all the classes it finds references to when it loads one class - so as soon as it tries to load your ModTE class in order to call the init method, it goes through the whole class and finds references to some which it can't find (because they aren't present on the server) and crashes immediately.

 

@SideOnly is okay to use in the right circumstances, but because of the way Java loads things it's safest to keep client and server side code in completely separate classes - putting a side annotation on a method is not completely reliable.

  • Like 1
Link to comment
Share on other sites

2 hours ago, Jay Avery said:

It's not that the method is being executed. It's just that Java (tries to) load all the classes it finds references to when it loads one class - so as soon as it tries to load your ModTE class in order to call the init method, it goes through the whole class and finds references to some which it can't find (because they aren't present on the server) and crashes immediately.

 

@SideOnly is okay to use in the right circumstances, but because of the way Java loads things it's safest to keep client and server side code in completely separate classes - putting a side annotation on a method is not completely reliable.

Thanks a lot, will start to do that from now on so I avoid this problems. ;)

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.



×
×
  • Create New...

Important Information

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