Jump to content

[SOLVED][1.7.2]My entity render causes server side crash`


Recommended Posts

Posted

Okay, I understand that rendering is supposed to happen on client side only, but I thought I was handling that by making my whole render class only client side, as follows:

 

package wildanimals.renderers;

 

import net.minecraft.client.model.ModelBase;

import net.minecraft.client.renderer.entity.RenderLiving;

import net.minecraft.entity.Entity;

import net.minecraft.entity.EntityLivingBase;

import net.minecraft.entity.passive.EntitySheep;

import net.minecraft.util.ResourceLocation;

 

import org.lwjgl.opengl.GL11;

 

import wildanimals.entities.EntityBigCat;

import cpw.mods.fml.relauncher.Side;

import cpw.mods.fml.relauncher.SideOnly;

 

@SideOnly(Side.CLIENT)

public class RenderBigCat extends RenderLiving

{

    private static final ResourceLocation normalTexture = new ResourceLocation("wildanimals:textures/entity/tiger/tiger.png");

    private static final ResourceLocation tamedTexture = new ResourceLocation("wildanimals:textures/entity/tiger/tiger_tame.png");

    private static final ResourceLocation angryTexture = new ResourceLocation("wildanimals:textures/entity/tiger/tiger_angry.png");

    private static final ResourceLocation tigerCollarTextures = new ResourceLocation("wildanimals:textures/entity/tiger/tiger_collar.png");

    private static final String __OBFID = "CL_00001036";

 

    public RenderBigCat(ModelBase par1ModelBase, ModelBase par2ModelBase, float par3)

    {

        super(par1ModelBase, par3);

        this.setRenderPassModel(par2ModelBase);

    }

 

    /**

    * Defines what float the third param in setRotationAngles of ModelBase is

    */

    protected float handleRotationFloat(EntityBigCat par1EntityBigCat, float par2)

    {

        return par1EntityBigCat.getTailRotation();

    }

 

    /**

    * Queries whether should render the specified pass or not.

    */

    protected int shouldRenderPass(EntityBigCat par1EntityBigCat, int par2, float par3)

    {

        if (par2 == 0 && par1EntityBigCat.getBigCatShaking())

        {

            float f1 = par1EntityBigCat.getBrightness(par3) * par1EntityBigCat.getShadingWhileShaking(par3);

            this.bindTexture(normalTexture);

            GL11.glColor3f(f1, f1, f1);

            return 1;

        }

        else if (par2 == 1 && par1EntityBigCat.isTamed())

        {

            this.bindTexture(tigerCollarTextures);

            int j = par1EntityBigCat.getCollarColor();

            GL11.glColor3f(EntitySheep.fleeceColorTable[j][0], EntitySheep.fleeceColorTable[j][1], EntitySheep.fleeceColorTable[j][2]);

            return 1;

        }

        else

        {

            return -1;

        }

    }

 

    /**

    * Returns the location of an entity's texture. Doesn't seem to be called unless you call Render.bindEntityTexture.

    */

    protected ResourceLocation getEntityTexture(EntityBigCat par1EntityBigCat)

    {

        return par1EntityBigCat.isTamed() ? tamedTexture : (par1EntityBigCat.isAngry() ? angryTexture : normalTexture);

    }

 

    /**

    * Queries whether should render the specified pass or not.

    */

    @Override

protected int shouldRenderPass(EntityLivingBase par1EntityLivingBase, int par2, float par3)

    {

        return this.shouldRenderPass((EntityBigCat)par1EntityLivingBase, par2, par3);

    }

 

    /**

    * Defines what float the third param in setRotationAngles of ModelBase is

    */

    @Override

protected float handleRotationFloat(EntityLivingBase par1EntityLivingBase, float par2)

    {

        return this.handleRotationFloat((EntityBigCat)par1EntityLivingBase, par2);

    }

 

    /**

    * Returns the location of an entity's texture. Doesn't seem to be called unless you call Render.bindEntityTexture.

    */

    @Override

protected ResourceLocation getEntityTexture(Entity par1Entity)

    {

        return this.getEntityTexture((EntityBigCat)par1Entity);

    }

}

 

 

However, when run with server run config from Eclipse I get following error:

 

[10:10:50] [server thread/ERROR] [net.minecraft.server.MinecraftServer]: Encountered an unexpected exception

java.lang.NoClassDefFoundError: net/minecraft/client/renderer/entity/Render

at java.lang.Class.forName0(Native Method) ~[?:1.7.0_51]

at java.lang.Class.forName(Class.java:270) ~[?:1.7.0_51]

...

Caused by: java.lang.ClassNotFoundException: net.minecraft.client.renderer.entity.Render

at net.minecraft.launchwrapper.LaunchClassLoader.findClass(LaunchClassLoader.java:188) ~[launchwrapper-1.9.jar:?]

 

 

 

So my question is really: besides making the render class client side only, what else do I have to make rendering client side only? I'm suspecting that the render registry entries in my main class should only be registered when on client side (I'm not doing this now)?  Do I have to do anything with the actual render methods in my entities?

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Posted

Yeah you should register your renderers client-side.

 

BTW, make sure you remove all the "__OBFID" field from your class, it fucks up the obfuscation

Don't PM me with questions. They will be ignored! Make a thread on the appropriate board for support.

 

1.12 -> 1.13 primer by williewillus.

 

1.7.10 and older versions of Minecraft are no longer supported due to it's age! Update to the latest version for support.

 

http://www.howoldisminecraft1710.today/

Posted

Okay, so assuming that I should only register my renderers on client side, how do I check for client side in the main class of my mod?  It doesn't seem like world.isRemote() is available there, also the @SideOnly doesn't seem too happy if I try it within my code.  And I don't think Minecraft.getMinecraft() works for this, especially since I'm not sure it exists even on client during the preInit stage.

 

What is safest way to check for whether you're on a server during preInit?

 

Or should renderers be registered later?

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Posted

You cannot reference anything client side only in code that does not have @SideOnly.

 

Use proxies.

 

Seriously. The only other way is to have a server side only and client side only preInit

Posted

You cannot reference anything client side only in code that does not have @SideOnly.

 

Use proxies.

 

Seriously. The only other way is to have a server side only and client side only preInit

 

I'm using 1.7.2 though and thought I could get away without the proxies (I did use these before in 1.6.4).

 

I actually did think about having two preInits, one for each side, but when I tried using @SideOnly to distinguish them Eclipse complained about having two methods with the same name.  Although maybe I can ignore that warning since I guess only the one for the proper side will be loaded?  I'll play around with this more.

 

Can someone using 1.7.2 share their code for registering renderer such that it only gets registered if on client side?  I must be missing something simple.

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Posted

What gave you the impression that you don't need proxies in 1.7?

 

I guess some misleading tutorials!  ;D  I had working 1.6.4 mods and then followed some tutorials for converting the mods to 1.7.2 and they didn't have the sided proxy stuff anymore so I figured it wasn't required (also because the @NetworkMod annotation wasn't needed I assumed it was related to proxy stuff).

 

I'll go back and re-implement my sided proxy stuff now that I know it is in fact still required.

 

 

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Posted

You cannot reference anything client side only in code that does not have @SideOnly.

 

Use proxies.

 

Seriously. The only other way is to have a server side only and client side only preInit

 

I actually did think about having two preInits, one for each side, but when I tried using @SideOnly to distinguish them Eclipse complained about having two methods with the same name.  Although maybe I can ignore that warning since I guess only the one for the proper side will be loaded?  I'll play around with this more.

 

 

You should still use proxies, but for a hypothetical situation, you could use LoadServer and LoadClient as the names of the methods as what matters is the @eventhandler.

Posted

Okay, solved.  I just re-implemented my SidedProxy stuff.  I will have to give some feedback to a couple tutorial authors to include this in their 1.7.2 conversion examples as I assumed the omission was purposeful (although I was suspicious at the time).

 

@Darty, yeah I was just thinking that -- it is really the event type that is passed that controls the call, not the name of the method itself.

 

But the proxy thing is the standard way for controlling what classes are used based on side, so I'll stick with that.

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

  • 3 months later...
Posted

Could you please post what you ended up using for v1.7.2 (or 1.7.10)? I've just run into the same thing, but I began modding with v1.7.2, so I've never learned proxies. I tried looking at older code, and I am bewildered by all of the differences.

 

I'm so frustrated, because my mod works PERFECTLY in Eclipse SP, but it blows up on launch as soon as I try to launch a real server. My error messages mirror your OP.

 

I've tried Googling "Minecraft Forge client proxy in 1.7.2", and I got only TWO hits (your thread and a v1.6.4 thread that mentioned 1.7.2 as an aside). That has me worried  :(

 

The debugger is a powerful and necessary tool in any IDE, so learn how to use it. You'll be able to tell us more and get better help here if you investigate your runtime problems in the debugger before posting.

Posted

Hey, the proxy thing isn't so complicated but does require a bit of understanding. 

 

Basically, rendering, sound and user input (keyboard / mouse) only really make sense on the client side.  Minecraft could have loaded all classes on server side (and tested isRemote before calling them to avoid calling client side stuff) but they figured that was wasteful so they made some classes @SideOnly.  That means the class or method so annotated doesn't even "exist" when running on that side.

 

The issue then is that you need to be aware if any of your code is calling classes that only exist on client side because they will crash if called from the server.

 

To solve this, there is the idea of a "proxy" class.  This is actually two classes, but only only one or the other is loaded as the proxy instance.  The client side has overrides for the server side (since there is always a server, it is mostly client stuff that causes trouble) and includes the client only stuff.  So you can call the same method like proxy.preInit() and it will do different stuff depending on which side is calling it.

 

You maybe can get the idea if you look at the main class and the CommonProxy and ClientProxy classes in some of my mods.  Here is the code for the mod that I was discussing at beginning of this thread: https://github.com/jabelar/WildAnimalsPlus-1.7.10/tree/master/src/main/java/com/blogspot/jabelarminecraft/wildanimals

 

 

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Posted

Hey, the proxy thing isn't so complicated but does require a bit of understanding. 

No kidding. On my first try, the client proxy itself became the offending class on the server, so all I accomplished was to move the error. Part of my problem is that the examples I've found have been v1.6.4 (and very complex mods). It's taking me a while to tease out the general proxy implementation details from the haystacks of mod-specific and Forge-version-specific context.

 

Basically, rendering, sound and user input (keyboard / mouse) only really make sense on the client side...

That's what I figured. What remains somewhat mysterious is how I refer to something that will work on the client without the mere mention blowing up on the server.

 

...there is the idea of a "proxy" class.  This is actually two classes, but only only one or the other is loaded as the proxy instance.

Okay, runtime polymorphism is old hat for me. What I haven't figured out is how I can even write the client-side instantiation without the server blowing sky high as soon as it tries to instantiate my main class (nothing within my main class even starts to run; my error now is during its construction). I'm obviously not doing a proper job of quarantine.

 

You maybe can get the idea if you look at the main class and the CommonProxy and ClientProxy classes in some of my mods: https://github.com/jabelar/WildAnimalsPlus-1.7.10/tree/master/src/main/java/com/blogspot/jabelarminecraft/wildanimals

Thanks, that should help. The mystery to me (for now) is how to write a "@SidedProxy(clientSide= ...)" statement. There are some very long strings in there with lots of dotted subparts that the compiler can't help me parse. Other example mods and tutorials have similarly long but differently dotted paths (and little or no context within which to interpret them). Since every tutorial I've seen so far simply tosses these strings at me without telling me what the parts mean, I haven't been able to write one of my own. Seeing your whole project, it looks as if each string is <package>.<class>, like an import statement.

 

I'll give that a try and see what blows up next. The good news is that my mod runs flawlessly inside of Eclipse, so I'm doing something right.

 

The debugger is a powerful and necessary tool in any IDE, so learn how to use it. You'll be able to tell us more and get better help here if you investigate your runtime problems in the debugger before posting.

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.