Jump to content

[1.8.9] [SOLVED] Registering a new mob entity?


DragonessAtHeart

Recommended Posts

Hello everyone.

 

I'm pretty new to modding with Forge and forums and I apologize if this is in the wrong place or anything.

 

I'm pulling my hair out trying to figure out how to properly register and render a new entity in 1.8.9.

 

I have no idea what the IRenderFactory is or how to use it and I'm not even really sure rendering is my only problem.

I have the entity class and the model class for the mob and a render class but I'm hitting a wall trying to find examples of how to do it properly with the new update. Everyone is just saying "use the registerEntityRenderingHandler" thing but I really have no idea specifically how to do this. This is my first mod.

 

Could someone out there help me out? Thank you!!

 

I have seen this topic:  [1.8]Error Spawning in Entities, and this one,  [1.8.9] Entity rendering registering recently changed?, but I need more information about how to actually do what they talk about.

 

Also I'm not sure how to link a post. >> Sorry....

 

Please be gentle...

Link to comment
Share on other sites

If you're targeting Java 6/7, just create an anonymous class that implements

IRenderFactory

and overrides

createRenderFor

to return a new instance of the your

Render

class.

 

If you're targeting Java 8, you can use a method reference to pass your

Render

class's constructor (

RenderMyEntity::new

) as an

IRenderFactory

instead.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Link to comment
Share on other sites

Could you maybe give an example of how to use it?

 

Well I am pretty lazy with my registry so I literally dump all my classes through a Proxy method:

@Override
public void sidedEntityRegistry(Class<? extends Entity> c){
	try {
		final Class cc = (Class<? extends Render>) c.getClassLoader().loadClass("rankshank/pikmine/client/render/entity/" + c.getName().substring(c.getName().lastIndexOf("Entity")).replace("Entity", "Render"));
		RenderingRegistry.registerEntityRenderingHandler(c, new IRenderFactory<Entity>(){
                            @Override 
                            public Render createRenderFor(RenderManager rm) {
                                try {
                                    return (Render) cc.getConstructor(RenderManager.class).newInstance(rm);
                                } catch(Exception e){
                                      e.printStackTrace();
                                return null;}}});
	    } catch (Exception e) {
		e.printStackTrace();
	    }
}

Works a treat though since I follow a set naming standard. You can just do direct class references if iteration is too 'scary'

I think its my java of the variables.

Link to comment
Share on other sites

I am trying to target Java 8, but thank you for mentioning both.

 

"you can use a method reference to pass your Render class's constructor (RenderMyEntity::new) as an IRenderFactory instead."

 

The render class here we are talking about is the new mob's render class?

 

I feel like I want to do something like this,

registerEntityRenderingHandler(EntityNewMob.class, IRenderFactory (RenderNewMob::new));

but that isn't how you do it.

 

Also oh my goodness RANKSHANK there is so much going on there!

 

I'll have to study that code to see if I can't figure out what is going on.

 

Can you tell me where I need to start researching to figure it out or try to explain it a bit more?

 

If you don't feel like it, that's cool. I can probably figure it out eventually. :)

Link to comment
Share on other sites

Can you tell me where I need to start researching to figure it out or try to explain it a bit more?

 

It's actually not too bad, the error handling just gunks it up a bit

 

Basically I'm working off the principle that all of my renderers are in rankshank/pikmine/client/render/entity/ and follow the naming format Render{EntityName}.class, their corresponding entity classes just need to follow the naming format Entity{EntityName}.class.

 

Using the known package and transforming the Entity prefix to the Render prefix, I then have a string handle for my Render class.

 

Then using that string handle I query the ClassLoader for the class object which I then create and instance of it using the Render(RenderManager) constructor, which is a consistent constructor throughout my render classes.

 

I then use that as the return value of my RenderFactory which registers the renderer.

 

It all runs off the expectation that I'll continue to follow the same format. I may have to switch to using hard coded strings so that I can subpackage my render folder.

I think its my java of the variables.

Link to comment
Share on other sites

I am trying to target Java 8, but thank you for mentioning both.

 

"you can use a method reference to pass your Render class's constructor (RenderMyEntity::new) as an IRenderFactory instead."

 

The render class here we are talking about is the new mob's render class?

 

I feel like I want to do something like this,

registerEntityRenderingHandler(EntityNewMob.class, IRenderFactory (RenderNewMob::new));

but that isn't how you do it.

 

The parentheses weren't part of the code. Just pass the method reference itself as the

IRenderFactory

argument, you don't need to explicitly cast to or specify that it's an

IRenderFactory

.

 

registerEntityRenderingHandler(EntityNewMob.class, RenderNewMob::new);

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Link to comment
Share on other sites

I'm sorry. I didn't mention that I had tried that already unsuccessfully.

 

I am now doing this:


registerEntityRenderingHandler(EntityGiantLizard.class, RenderGiantLizard::new);

 

Which tells me that the registerEntityRenderingHandler method is not defined for my client proxy.

 

I've imported

import net.minecraft.client.Minecraft;

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

import net.minecraftforge.fml.client.registry.RenderingRegistry;

import net.minecraftforge.fml.common.Mod.Instance;

import net.minecraftforge.fml.common.event.FMLInitializationEvent;

import net.minecraftforge.fml.common.event.FMLPostInitializationEvent;

import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;

import net.minecraftforge.fml.common.registry.EntityRegistry;

import net.minecraftforge.fml.common.registry.EntityRegistry.EntityRegistration;

import net.minecraftforge.fml.common.registry.LanguageRegistry;

import net.minecraftforge.fml.relauncher.Side;

 

import net.minecraftforge.fml.client.registry.IRenderFactory;

import net.minecraftforge.fml.client.registry.ClientRegistry;

import com.dragonessatheart.firstmod.*;

 

So unless I'm forgetting something, I'm not sure what to do.

 

When I try this:

RenderingRegistry.registerEntityRenderingHandler(EntityGiantLizard.class, RenderGiantLizard::new);

 

It says:

The method registerEntityRenderingHandler(Class<? extends Entity>, Render<? extends Entity>) in the type RenderingRegistry is not applicable for the arguments (Class<EntityGiantLizard>, RenderGiantLizard::new)

 

Which I honestly don't know how to decipher.

 

Thank you!

Link to comment
Share on other sites

The version of forge is: forge-1.8.9-11.15.1.1722, at least that's what it says on the changelog txt name.

 

I know it's at least 1.8.9. The recommended one.

 

RenderGiantLizard is here.

 

 

package com.dragonessatheart.firstmod;

import net.minecraft.client.Minecraft;
import net.minecraft.client.model.ModelBase;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.renderer.entity.RenderLiving;
import net.minecraft.client.renderer.entity.RenderManager;
import net.minecraft.client.renderer.entity.RendererLivingEntity;
import net.minecraft.client.renderer.entity.layers.LayerWolfCollar;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLiving;
import net.minecraft.entity.EntityLivingBase;
import com.dragonessatheart.firstmod.EntityGiantLizard;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

@SideOnly(Side.CLIENT)
public class RenderGiantLizard extends RendererLivingEntity {

	private static final ResourceLocation giantLizardTextures = new ResourceLocation("assets/firstmod/textures/entity/giantlizard/giantlizard.png");
  
	RenderManager renderManager = Minecraft.getMinecraft().getRenderManager();
    


	public RenderGiantLizard(RenderManager renderManager, ModelBase model, float shadowSize) //, float scale, String texturePath)
    {
        super(renderManager, model, shadowSize);

    }
     
  

    /**
     * Returns the location of an entity's texture. Doesn't seem to be called unless you call Render.bindEntityTexture.
     */
    protected ResourceLocation getEntityTexture(Entity entity)
    {
        return this.getEntityTexture((EntityGiantLizard)entity);
    }
    
    /**
     * Returns the location of an entity's texture. Doesn't seem to be called unless you call Render.bindEntityTexture.
     */
    protected ResourceLocation getEntityTexture(EntityGiantLizard entity)
    {
        return giantLizardTextures;
    }
    
     //no idea what this is
    public void func_177135_a(EntityGiantLizard p_177135_1_, double p_177135_2_, double p_177135_4_, double p_177135_6_, float p_177135_8_, float p_177135_9_)
    {
        super.doRender((EntityLiving)p_177135_1_, p_177135_2_, p_177135_4_, p_177135_6_, p_177135_8_, p_177135_9_);
    }

    

    /**
     * Actually renders the given argument. This is a synthetic bridge method, always casting down its argument and then
     * handing it off to a worker function which does the actual work. In all probabilty, the class Render is generic
     * (Render<T extends Entity>) and this method has signature public void func_76986_a(T entity, double d, double d1,
     * double d2, float f, float f1). But JAD is pre 1.5 so doe
     */
    public void doRender(EntityLiving entity, double x, double y, double z, float p_76986_8_, float partialTicks)
    {
        this.func_177135_a((EntityGiantLizard)entity, x, y, z, p_76986_8_, partialTicks);
    }

    /**
     * Defines what float the third param in setRotationAngles of ModelBase is
     */
//	    protected float handleRotationFloat(EntityLivingBase p_77044_1_, float p_77044_2_)
//	    {
//	        return this.func_180593_a((EntityGiantLizard)p_77044_1_, p_77044_2_);
//	    }

    /**
     * Actually renders the given argument. This is a synthetic bridge method, always casting down its argument and then
     * handing it off to a worker function which does the actual work. In all probabilty, the class Render is generic
     * (Render<T extends Entity>) and this method has signature public void func_76986_a(T entity, double d, double d1,
     * double d2, float f, float f1). But JAD is pre 1.5 so doe
     */ 
    
    
    
    public void doRender(EntityLivingBase entity, double x, double y, double z, float p_76986_8_, float partialTicks)
    {
        this.func_177135_a((EntityGiantLizard)entity, x, y, z, p_76986_8_, partialTicks);
    }

    /**
     * Actually renders the given argument. This is a synthetic bridge method, always casting down its argument and then
     * handing it off to a worker function which does the actual work. In all probabilty, the class Render is generic
     * (Render<T extends Entity>) and this method has signature public void func_76986_a(T entity, double d, double d1,
     * double d2, float f, float f1). But JAD is pre 1.5 so doe
     */
    public void doRender(Entity entity, double x, double y, double z, float p_76986_8_, float partialTicks)
    {

    	this.func_177135_a((EntityGiantLizard)entity, x, y, z, p_76986_8_, partialTicks);
    }
}

 

 

 

 

Thank you so much!

Link to comment
Share on other sites

For a method reference to be used as an interface, the method must have the same signature as the interface's method.

 

IRenderFactory#createRenderFor

takes a single

RenderManager

argument and returns a

Render

, your method must do the same. Constructors implicitly return an instance of their class, so you just need to match the arguments.

 

You don't need to create your own

renderManager

field,

Render#renderManager

already exists with protected access.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

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.