Jump to content

[1.9.4] Registering entity renderer


SevenDeLeven

Recommended Posts

I took a look at this forum, and I tried doing the constructor for the Render class, and all it takes is the render manager, not the model. When I run the game, the entity doesn't render, but it works. All the entity is, is something that extends the arrow class. The methods that the post uses aren't able to be overridden, most likely that they aren't there anymore. I think it doesn't work because the constructor doesn't use the model class, and I'm wondering where that can be initiated and created.

 

This is the class that registers the entities and the renders (The only one I'm worried about is the EntityExplosiveArrow)

 

 

package com.kraftymods.mod.init;

public class ModEntities {
   
   public static void register(){
      EntityRegistry.registerModEntity(EntityThrownMonsterEgg.class, "ThrownMonsterEgg", 8849, ModMain.instance, 0, 20, true);
      EntityRegistry.registerModEntity(EntityExplosiveArrow.class, "ExplosiveArrow", 8850, ModMain.instance, 0, 20, true);
   }
   
   public static void registerRenders(){
      RenderingRegistry.registerEntityRenderingHandler(EntityExplosiveArrow.class, new IRenderFactory(){
         @Override
         public Render createRenderFor(RenderManager manager) {
            return new RenderExplosiveArrow(manager);
         }
      });
   }
   
}

 

 

 

And this is the RenderExplosiveArrow class

 

 

package com.kraftymods.mod.entity;

public class RenderExplosiveArrow extends Render{

public ResourceLocation texture = new ResourceLocation(Reference.MOD_ID+":textures/entity/explosiveArrow.png");

public RenderExplosiveArrow(RenderManager renderManager) {
	super(renderManager);
}

protected ResourceLocation getEntityTexture(Entity entity) {
	return texture;
}

}

 

 

Link to comment
Share on other sites

I have to ask - how do you think rendering works? You just put texture and it appears? Wtf?

Ye, you have a renderer, but where is rendering code?!

 

Registration seems good, base of renderer almost, but aside from that there is no rendering involved.

 

1. Render class has entity generic type! Use Render<EntityExplosiveArrow>!

2. You need to write your rendering code:

* Learn GL and vertex drawing.

* Lookup RenderArrow class for LITERALLY direct code on rendering.

* Write your own.

OR

* Extend RenderArrow, in which case your EntityExplosiveArrow needs to extend EntityArrow.

1.7.10 is no longer supported by forge, you are on your own.

Link to comment
Share on other sites

I extended the RenderArrow class,

 

 

public class RenderExplosiveArrow<T extends EntityExplosiveArrow> extends RenderArrow<T>{

public ResourceLocation texture = new ResourceLocation(Reference.MOD_ID+":textures/entity/explosiveArrow.png");

public RenderExplosiveArrow(RenderManager renderManager) {
	super(renderManager);
}

protected ResourceLocation getEntityTexture(T entity) {
	return texture;
}

@Override
public void doRender(T entity, double x, double y, double z, float entityYaw, float partialTicks) {
	super.doRender(entity, x, y, z, entityYaw, partialTicks);
}

}

 

 

 

And I created the object,

 

 

RenderingRegistry.registerEntityRenderingHandler(EntityExplosiveArrow.class, new IRenderFactory(){
@Override
public Render createRenderFor(RenderManager manager) {
	return new RenderExplosiveArrow<EntityExplosiveArrow>(manager);
}
});

 

 

 

 

It still doesn't work, but all of the steps you told me to take were taken, maybe theres some code I'm missing?

 

 

And on a personal note, I didn't expect it to work, it never did, I couldn't find a way to implement the model that I made. I haven't programmed a mod for 1.9.4 yet, and the format is new, and making entities is something I almost never do (Last time was a year ago on 1.8 ).

Link to comment
Share on other sites

1st of all, you don't have problem with "Oh, I haven't made a mod in years, it so different now!". Your problem is rather "I don't know Java, but I think I do.".

 

There is literally nothing hard in looking a super class or doing research on source. Besides - why on earth would you override method, to just then call super.method and do nothing else? What's the point...

 

Anyway - If you are going to extend RenderArrow - it uses very specific calculations/rendering reserved for exactly that - ARROWS.

If you want to use its renderer you have to use same texture format and other shit (here - entity has to extend EntityArrow and you can't touch any important variables inside said arrow, because they are used by renderer to do shit like rendering rotation).

 

So yeah, you are not giving full code so right now I can only tell you - make your texture SAME as arrows and check if it works.

1.7.10 is no longer supported by forge, you are on your own.

Link to comment
Share on other sites

I have just tested with the same texture as arrows, and it still doesn't work, and if you want specific code, I will give it to you, just specify what you want.

 

Also, I know how to program in java, I make games, but I made that useless method for debugging, and accidentally left it. I always look at source code before going to the forums, but I can't find how entities are registered as far as rendering goes, thats it.

Link to comment
Share on other sites

Classes: Main mod, proxies, entity, renderer and other related stuff (maybe rendering events?)

 

I totally forgot to ask before - when are you calling #registerRenders()? (well, I'll se, just give sources).

Note: It should (must) be called in pre-init.

 

P.S: Okay, that "You don't know Java" was far fetched, but shit I read here sometimes... That argument is true in most cases.

1.7.10 is no longer supported by forge, you are on your own.

Link to comment
Share on other sites

Here's my code

 

ModMain Class

 

 

 

@Mod(name = Reference.MOD_NAME, modid = Reference.MOD_ID, version = Reference.VERSION, acceptedMinecraftVersions = Reference.ACCEPTEDMCV)
public class ModMain {

@Instance
public static ModMain instance;

@SidedProxy(clientSide = Reference.CLIENT_PROXY, serverSide = Reference.COMMON_PROXY)
public static CommonProxy proxy;

@EventHandler
public static void preInit(FMLPreInitializationEvent event){
	ModItems.init();
	ModBlocks.init();
	ModItems.register();
	ModBlocks.register();
	ModEntities.register();
	ModRecipes.init();
	ModEntities.registerRenders();
}

@EventHandler
public static void init(FMLInitializationEvent event){
	proxy.registerRenders();
}

@EventHandler
public static void postInit(FMLPostInitializationEvent event){

}

}

 

 

 

Reference Class (Cut to relevant Information, removing Item and Block enumerations)

 

 

 

public class Reference {

public static final String MOD_ID = "moarweapons";
public static final String MOD_NAME = "Moar Wepons";
public static final String VERSION = "1.0B";
public static final String ACCEPTEDMCV = "[1.9.4]";

public static final String CLIENT_PROXY = "com.kraftymods.mod.proxy.ClientProxy";
public static final String COMMON_PROXY = "com.kraftymods.mod.proxy.CommonProxy";

public static final Random r = new Random();

}

 

 

 

ClientProxy Class

 

Common Proxy doesn't have anything in its registerRenders method, as it should be, so I won't show it

 

 

 

public class ClientProxy extends CommonProxy implements ICommonProxy {

public void registerRenders(){
	ModItems.registerRenders();
	ModBlocks.registerRenders();
	Minecraft.getMinecraft().getItemColors().registerItemColorHandler(new IItemColor(){
		@Override
		public int getColorFromItemstack(ItemStack stack, int tintIndex) {
			Map<String, EntityEggInfo> eggs = EntityList.ENTITY_EGGS;
			int index = 0;
			for (Map.Entry<String, EntityEggInfo> egg : eggs.entrySet()){
				if (index == stack.getMetadata()){
					if (tintIndex == 0){
						return egg.getValue().primaryColor;
					} else if (tintIndex == 1){
						return egg.getValue().secondaryColor;
					} else {
						return 1;
					}
				}
				index++;
			}
			return 1;
		}}, ModItems.spawnerStaff);
}

}

 

 

 

EntityExplosiveArrow Class

 

 

 

public class EntityExplosiveArrow extends EntityArrow{

public EntityExplosiveArrow(World worldIn) {
	super(worldIn);
}

public EntityExplosiveArrow(World worldIn, double x, double y, double z) {
	super(worldIn, x, y, z);
}

public EntityExplosiveArrow(World worldIn, EntityLivingBase shooter) {
	super(worldIn, shooter);
}

@Override
protected void onHit(RayTraceResult raytraceResultIn) {
	if (raytraceResultIn.entityHit == null || (raytraceResultIn.entityHit != null && raytraceResultIn.entityHit != shootingEntity)){
		super.onHit(raytraceResultIn);
		this.worldObj.createExplosion(null, this.posX, this.posY, this.posZ, 3.0f, true);
		this.setDead();
	}
}

@Override
protected ItemStack getArrowStack() {
	return new ItemStack(ModItems.explosiveArrow, 1);
}

}

 

 

 

RenderExplosiveArrow Class

 

 

 

public class RenderExplosiveArrow<T extends EntityExplosiveArrow> extends RenderArrow<T>{

public ResourceLocation texture = new ResourceLocation(Reference.MOD_ID+":textures/entity/explosiveArrow.png");

public RenderExplosiveArrow(RenderManager renderManager) {
	super(renderManager);
}

protected ResourceLocation getEntityTexture(T entity) {
	return texture;
}

@Override
public void doRender(T entity, double x, double y, double z, float entityYaw, float partialTicks) {
	super.doRender(entity, x, y, z, entityYaw, partialTicks);
}

}

 

 

 

I don't know what you mean't by "maybe rendering events?", I think that might be something that I am missing, causing the problem?

 

And, thanks for your time, this post is a bit extensive, and is consuming a lot of your time.

Link to comment
Share on other sites

Oh my god.

Registration seems good

Yeah... right...

 

Please read javadoc of EntityRegistry#registerModEntity.

Your tracking range = 0, which means client will probably never even spawn client-side arrow.

For vanilla arrows range is 64 (such values can be found in EntityTracker).

 

P.S:

You should move this "ModEntities.registerRenders();" to client proxy.

1.7.10 is no longer supported by forge, you are on your own.

Link to comment
Share on other sites

I'm sorry that I wasted your time, it was right there and I never realized it. My bad, when I read the parameter in the autoFill (whatever it's called) I saw trackingRange, which seemed odd to me, but it also never occurred to me to check what it is, but thanks so much, and I did learn a couple other things on the way so this wasn't totally useless. Thanks anyway!

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.