Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

Hello@All ,

 

so i got only 1 problem,

my entity dont want to attack me , but i know whats missing,

 

in 1.7.10 there was a function like :" AIAttackOnColide"

i cant find it for 1.10 -_-

 

heres my entity class:

 

public class EntityModelTest extends EntityMob{

public EntityModelTest(World worldIn) {
	super(worldIn);

	//AI Components
	this.tasks.addTask(1, new EntityAISwimming(this));
	this.tasks.addTask(2, new EntityAIAttackMelee(this, 1.0D, false));
	this.tasks.addTask(3, new EntityAIMoveTowardsRestriction(this, 1.0D));
	this.tasks.addTask(4, new EntityAIWander(this, 1.0D));
	this.tasks.addTask(5, new EntityAIWatchClosest(this, EntityPlayer.class, 20F));
	this.tasks.addTask(6, new EntityAILookIdle(this));

	this.setSize(0.6f, 1.5f);
}

@Override
protected void applyEntityAttributes()
{
  super.applyEntityAttributes();
	this.getEntityAttribute(SharedMonsterAttributes.FOLLOW_RANGE).setBaseValue(35.0D);
	this.getEntityAttribute(SharedMonsterAttributes.MOVEMENT_SPEED).setBaseValue(0.23000000417232513D);
	this.getEntityAttribute(SharedMonsterAttributes.ATTACK_DAMAGE).setBaseValue(4.0D);
	this.getEntityAttribute(SharedMonsterAttributes.MAX_HEALTH).setBaseValue(1000.0D);
}

 @Override
 public void readEntityFromNBT(NBTTagCompound nbt)
 {
  super.readEntityFromNBT(nbt);
 }

 @Override
 public void writeEntityToNBT(NBTTagCompound nbt)
 {
  super.writeEntityToNBT(nbt);
 }

 @Override
 public boolean attackEntityAsMob(Entity entity){
  super.attackEntityAsMob(entity);
  return entity.attackEntityFrom(DamageSource.causeMobDamage(this), 1);
 }

protected boolean isAIEnabled()
{
return true;
}

  public boolean onUpdate(EntityLivingBase mob)
  {
    if ((getAttackTarget() != null) && 
      ((getAttackTarget() instanceof EntityPlayer))) {
      tryAbility(mob, getAttackTarget());
    }
    return onUpdate(mob);
  }

  private long nextAbilityUse = 0L;
  
  private void tryAbility(EntityLivingBase mob, EntityLivingBase target)
  {
    if ((target == null) || (target.getRidingEntity() != null) || (!mob.canEntityBeSeen(target))) {
      return;
    }
    long time = System.currentTimeMillis();
    if ((time > this.nextAbilityUse) && 
      (mob.getDistanceToEntity(target) > 3.0F) && 
      (target.worldObj.canBlockSeeSky(new BlockPos(MathHelper.floor_double(target.posX), MathHelper.floor_double(target.posY), MathHelper.floor_double(target.posZ)))))
    {
      this.nextAbilityUse = (time + 15000L);
      mob.worldObj.addWeatherEffect(new EntityLightningBolt(mob.worldObj, target.posX, target.posY - 1.0D, target.posZ, false));
    }
  }

    protected boolean canDropLoot()
    {
        return false;
    }

}

Let me just go look at vanilla code for a second.

 

Oh look at that.

 

EntityAIZombieAttack extends EntityAIAttackMelee

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

  • Author

Let me just go look at vanilla code for a second.

 

Oh look at that.

 

EntityAIZombieAttack extends EntityAIAttackMelee

 

im using in my tasks "EntityAIAttackMelee" but hes not attacking me back if i hit him :(

EntityAIAttackMelee isn't an "attack you when you attack it" it's the "I bump into you and deal damage" behavior.

 

You might also want to look at what makes EntityAIZombieAttack different.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

  • Author

EntityAIAttackMelee isn't an "attack you when you attack it" it's the "I bump into you and deal damage" behavior.

 

You might also want to look at what makes EntityAIZombieAttack different.

 

EDIT: i want to try it with "EntityAIAttackMelee" , so my entity is attacking me now ..

 

but hes not using "tryability" ... idk why ..

 

hers the code:

 

public class EntityModelTest extends EntityMob{

public EntityModelTest(World worldIn) {
	super(worldIn);

	//AI Components
	this.tasks.addTask(1, new EntityAISwimming(this));
	this.tasks.addTask(2, new EntityAIAttackMelee(this, 1.0D, false));
	this.tasks.addTask(3, new EntityAIMoveTowardsRestriction(this, 1.0D));
	this.tasks.addTask(4, new EntityAIWander(this, 1.0D));
	this.tasks.addTask(5, new EntityAIWatchClosest(this, EntityPlayer.class, 20F));
	this.tasks.addTask(6, new EntityAILookIdle(this));

	this.targetTasks.addTask(0, new EntityAINearestAttackableTarget(this, EntityPlayer.class , true));

	this.setSize(0.6f, 1.5f);
}

@Override
protected void applyEntityAttributes()
{
  super.applyEntityAttributes();
	this.getEntityAttribute(SharedMonsterAttributes.FOLLOW_RANGE).setBaseValue(35.0D);
	this.getEntityAttribute(SharedMonsterAttributes.MOVEMENT_SPEED).setBaseValue(0.23000000417232513D);
	this.getEntityAttribute(SharedMonsterAttributes.ATTACK_DAMAGE).setBaseValue(4.0D);
	this.getEntityAttribute(SharedMonsterAttributes.MAX_HEALTH).setBaseValue(1000.0D);
}

protected void addRandomArmor() {

	this.setItemStackToSlot(EntityEquipmentSlot.OFFHAND, new ItemStack(Items.SHIELD));
}

protected boolean isAIEnabled()
{
return true;
}

  public boolean onUpdate(EntityLivingBase mob)
  {
    if ((getAttackTarget() != null) && 
      ((getAttackTarget() instanceof EntityPlayer))) {
      tryAbility(mob, getAttackTarget());
    }
    return onUpdate(mob);
  }

  private long nextAbilityUse = 0L;
  
  private void tryAbility(EntityLivingBase mob, EntityLivingBase target)
  {
    if ((target == null) || (target.getRidingEntity() != null) || (!mob.canEntityBeSeen(target))) {
      return;
    }
    long time = System.currentTimeMillis();
    if ((time > this.nextAbilityUse) && 
      (mob.getDistanceToEntity(target) > 3.0F) && 
      (target.worldObj.canBlockSeeSky(new BlockPos(MathHelper.floor_double(target.posX), MathHelper.floor_double(target.posY), MathHelper.floor_double(target.posZ)))))
    {
      this.nextAbilityUse = (time + 15000L);
      mob.worldObj.addWeatherEffect(new EntityLightningBolt(mob.worldObj, target.posX, target.posY - 1.0D, target.posZ, false));
    }
  }

    protected boolean canDropLoot()
    {
        return false;
    }
    
    protected SoundEvent getAmbientSound() {
    	return null;
    }
    
    protected SoundEvent getHurtSound() {
    	return null;
    }
    
    protected SoundEvent getDeathSound() {
    	return null;
    }
    
	 @Override
	 public void readEntityFromNBT(NBTTagCompound nbt)
	 {
	  super.readEntityFromNBT(nbt);
	 }

	 @Override
	 public void writeEntityToNBT(NBTTagCompound nbt)
	 {
	  super.writeEntityToNBT(nbt);
	 }

}

 

if someone could help me :S

  • Author

EDIT :S

EntityAIAttackMelee is a vanilla class and wont call you private method of tryAbility.

 

 

:/ hmm so how could i do it,

 

i did a class "OnUpdate" and he doesnt use it, or do i need to use it in a class?

 

(Please know that its my first entityclass with abilitys that i ever code, so for any help im very thankfull)

 

	  public boolean onUpdate(EntityLivingBase mob)
  {
    if ((getAttackTarget() != null) && 
      ((getAttackTarget() instanceof EntityPlayer))) {
      tryAbility(mob, getAttackTarget());
    }
    return onUpdate(mob);
  }

  private long nextAbilityUse = 0L;
  
  private void tryAbility(EntityLivingBase mob, EntityLivingBase target)
  {
    if ((target == null) || (target.getRidingEntity() != null) || (!mob.canEntityBeSeen(target))) {
      return;
    }
    long time = System.currentTimeMillis();
    if ((time > this.nextAbilityUse) && 
      (mob.getDistanceToEntity(target) > 0.0F));
      //(target.worldObj.canBlockSeeSky(new BlockPos(MathHelper.floor_double(target.posX), MathHelper.floor_double(target.posY), MathHelper.floor_double(target.posZ)))))
    {
      this.nextAbilityUse = (time + 0L);
      mob.worldObj.addWeatherEffect(new EntityLightningBolt(mob.worldObj, target.posX, target.posY - 1.0D, target.posZ, false));
    }
  }

 

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

Important Information

By using this site, you agree to our Terms of Use.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.