Jump to content

Recommended Posts

Posted

My mob won't attack or even acknowledge the player.

It should have everything else it needs from extending EntityMob, and I don't see any classes like EntityZombie, etc, doing anything special...

Is setting its AI not enough?

public class Hunter extends EntityMob
{
	public Hunter(World world)
	{
		super(world);
		this.experienceValue = 30;
		this.setSize(0.5F, 1.8F);
	}

	@Override
	protected void applyEntityAttributes()
	{
		this.getAttributeMap().registerAttribute(SharedMonsterAttributes.MAX_HEALTH).setBaseValue(50);
		this.getAttributeMap().registerAttribute(SharedMonsterAttributes.KNOCKBACK_RESISTANCE).setBaseValue(0.01);
		this.getAttributeMap().registerAttribute(SharedMonsterAttributes.ATTACK_DAMAGE).setBaseValue(4);
		this.getAttributeMap().registerAttribute(SharedMonsterAttributes.ATTACK_SPEED);
		this.getAttributeMap().registerAttribute(SharedMonsterAttributes.MOVEMENT_SPEED);
		this.getAttributeMap().registerAttribute(SharedMonsterAttributes.FOLLOW_RANGE);
		this.getAttributeMap().registerAttribute(SharedMonsterAttributes.LUCK);
		this.getAttributeMap().registerAttribute(SharedMonsterAttributes.ARMOR);
		this.getAttributeMap().registerAttribute(SharedMonsterAttributes.ARMOR_TOUGHNESS);
	}
 
	@Override
	protected void initEntityAI()
	{
		this.tasks.addTask(0, new EntityAISwimming(this));
		this.tasks.addTask(5, new EntityAIMoveTowardsRestriction(this, 1.0D));
		this.tasks.addTask(6, new EntityAIMoveThroughVillage(this, 1.0D, false));
		this.tasks.addTask(7, new EntityAIWanderAvoidWater(this, 1.0D));
		this.tasks.addTask(8, new EntityAIWatchClosest(this, EntityPlayer.class, 8.0F));
		this.tasks.addTask(8, new EntityAILookIdle(this));
		this.targetTasks.addTask(1, new EntityAINearestAttackableTarget(this, EntityPlayer.class, true));
	}
 
  	protected boolean canEquipItem(ItemStack stack)
	{
		return stack.getItem() instanceof ItemSword || stack.getItem() instanceof MeleeWeapon;
	}
 
	@Nullable
	public IEntityLivingData onInitialSpawn(DifficultyInstance difficulty, @Nullable IEntityLivingData livingdata)
	{
		this.setItemStackToSlot(EntityEquipmentSlot.MAINHAND, new ItemStack(Items.IRON_SWORD));
		return livingdata;
	}
 
	public float getEyeHeight()
	{
		return 1.75F;
	}
 
	protected boolean isValidLightLevel()
	{
		return true;
	}
}

 

Posted (edited)

Where did applyEntityAI() go? You probably need that.

You don't need the @Override in the applyEntityAttributes, and you need to call the super method on that. Look at the EntityZombie class.

 

EDIT: sorry, I was looking at 1.10 source, this may or may not work for you.

 

EDIT 2: Yes, my suggestion is still the same, look at the EntityZombie class.

Edited by Leomelonseeds

Apparently I'm addicted to these forums and can't help but read all the posts. So if I somehow help you, please click the "Like This" button, it helps.

Posted
21 hours ago, Leomelonseeds said:

Where did applyEntityAI() go? You probably need that.

I only see that in EntityZombie. It seems to be pretty useless and it's not in a super class, so why would I use it?

Posted
21 hours ago, Leomelonseeds said:

You don't need the @Override in the applyEntityAttributes, and you need to call the super method on that

 

Apparently I'm addicted to these forums and can't help but read all the posts. So if I somehow help you, please click the "Like This" button, it helps.

Posted (edited)
3 minutes ago, Leomelonseeds said:

 

I'm doing everything in that method that's in all super methods, so that shouldn't matter...

Edited by Eria8
Posted
Just now, Leomelonseeds said:

Still, try. You never know whats gonna work.

	@Override
	protected void applyEntityAttributes()
	{
		super.applyEntityAttributes();
		this.getAttributeMap().registerAttribute(SharedMonsterAttributes.MAX_HEALTH).setBaseValue(50);
		this.getAttributeMap().registerAttribute(SharedMonsterAttributes.KNOCKBACK_RESISTANCE).setBaseValue(0.01);
		this.getAttributeMap().registerAttribute(SharedMonsterAttributes.ATTACK_DAMAGE).setBaseValue(4);
	}

If I do it that way, every time I try to spawn the mob it cancels the spawn and spams this error: "Caused by: java.lang.IllegalArgumentException: Attribute is already registered!".

 

So I completely removed the method, so that it should all be default attributes, and it still changed nothing. The mob still doesn't target the player. Attributes are not the problem.

Posted

I think you need to add something like this: this.tasks.addTask(2, new EntityAIZombieAttack(this, 1.0D, false));

Apparently I'm addicted to these forums and can't help but read all the posts. So if I somehow help you, please click the "Like This" button, it helps.

Posted
On 2/14/2017 at 7:06 PM, Leomelonseeds said:

I think you need to add something like this: this.tasks.addTask(2, new EntityAIZombieAttack(this, 1.0D, false));

This is what I was looking for. I thought that was something else, didn't see that it extended the EntityAIMeleeAttack which apparently now gives mobs the AI to actually attack. Now just have to fix its glitchy movement... Thanks!

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.