Jump to content

[1.12.2] What's wrong with EntityAINearestAttackableTarget?


SapphireSky

Recommended Posts

I'm trying to make a mob (extends EntityMob) and am basically copying tasks from existing mobs, but EntityAINearestAttackableTarget is giving me warnings that it's generic.

This is the default code, in any given mob class with a big yellow underline in Eclipse:

this.targetTasks.addTask(1, new EntityAINearestAttackableTarget(this, EntityPlayer.class, true));
this.targetTasks.addTask(2, new EntityAINearestAttackableTarget(this, EntityVillager.class, false));
this.targetTasks.addTask(3, new EntityAINearestAttackableTarget(this, EntityIronGolem.class, true));

 

Yet if I apply the suggested fix, it doesn't show a warning:

this.targetTasks.addTask(1, new EntityAINearestAttackableTarget<EntityPlayer>(this, EntityPlayer.class, true));
this.targetTasks.addTask(2, new EntityAINearestAttackableTarget<EntityVillager>(this, EntityVillager.class, false));
this.targetTasks.addTask(3, new EntityAINearestAttackableTarget<EntityIronGolem>(this, EntityIronGolem.class, true));

 

My question is, why? Why does it give me a warning if it's the Vanilla code that obviously works?

Is it going to be problematic if I ignore the warning? Or if I fix the warning?

  • Like 1
Link to comment
Share on other sites

1 hour ago, SapphireSky said:

I'm trying to make a mob (extends EntityMob) and am basically copying tasks from existing mobs, but EntityAINearestAttackableTarget is giving me warnings that it's generic.

This is the default code, in any given mob class with a big yellow underline in Eclipse:


this.targetTasks.addTask(1, new EntityAINearestAttackableTarget(this, EntityPlayer.class, true));
this.targetTasks.addTask(2, new EntityAINearestAttackableTarget(this, EntityVillager.class, false));
this.targetTasks.addTask(3, new EntityAINearestAttackableTarget(this, EntityIronGolem.class, true));

 

Yet if I apply the suggested fix, it doesn't show a warning:


this.targetTasks.addTask(1, new EntityAINearestAttackableTarget<EntityPlayer>(this, EntityPlayer.class, true));
this.targetTasks.addTask(2, new EntityAINearestAttackableTarget<EntityVillager>(this, EntityVillager.class, false));
this.targetTasks.addTask(3, new EntityAINearestAttackableTarget<EntityIronGolem>(this, EntityIronGolem.class, true));

 

My question is, why? Why does it give me a warning if it's the Vanilla code that obviously works?

Is it going to be problematic if I ignore the warning? Or if I fix the warning?

No it's completely fine if you leave it with the yellow underline. It just wants you to specify a type argument.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Link to comment
Share on other sites

Vanilla code is decompiled, so it's not perfect.

Generics are erased, so List<String> becomes just List once compiled. So it is hard for the decompiler to get back this information.


Raw types (what Eclipse warns you about) are a legacy feature of Java and should not be used. So no, it is not "completely fine".

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
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.