Jump to content

Mob AI bug, randomly just stands still, knocking up instead of back.


Recommended Posts

Posted

Hi,

 

So I'm having two issues with the AI of this mob.

Issue#1: Sometimes the mob randomly just decides to stop chasing and bounces up and down for a few seconds before resuming chasing.

 

Issue#2: No matter how I change the line : addVelocity(this.motionX * 2.0D, 2.0D, this.motionZ * 2.00D); , the mob always knocks me up into the air rather than backwards. It also only knocks me up after I hit it at least once.

 

When I don't use the new AI, neither of these happen but I can't get the mob to move above normal speed.

 

 

import net.minecraft.block.Block;

import net.minecraft.entity.Entity;

import net.minecraft.entity.EntityLiving;

import net.minecraft.entity.SharedMonsterAttributes;

import net.minecraft.entity.ai.EntityAIAttackOnCollide;

import net.minecraft.entity.ai.EntityAIHurtByTarget;

import net.minecraft.entity.ai.EntityAILookIdle;

import net.minecraft.entity.ai.EntityAIMoveThroughVillage;

import net.minecraft.entity.ai.EntityAIMoveTowardsRestriction;

import net.minecraft.entity.ai.EntityAINearestAttackableTarget;

import net.minecraft.entity.ai.EntityAISwimming;

import net.minecraft.entity.ai.EntityAIWander;

import net.minecraft.entity.ai.EntityAIWatchClosest;

import net.minecraft.entity.monster.EntityMob;

import net.minecraft.entity.passive.EntityVillager;

import net.minecraft.entity.player.EntityPlayer;

import net.minecraft.potion.Potion;

import net.minecraft.potion.PotionEffect;

import net.minecraft.world.World;

 

public class EntityCharger extends EntityMob {

 

public EntityCharger(World par1World) {

super(par1World);

this.tasks.addTask(0, new EntityAISwimming(this));

        this.tasks.addTask(2, new EntityAIAttackOnCollide(this, EntityPlayer.class, 1.0D, false));

        this.tasks.addTask(4, new EntityAIAttackOnCollide(this, EntityVillager.class, 1.0D, true));

        this.tasks.addTask(5, new EntityAIMoveTowardsRestriction(this, 1.0D));

        this.tasks.addTask(6, new EntityAIMoveThroughVillage(this, 1.0D, false));

        this.tasks.addTask(7, new EntityAIWander(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 EntityAIHurtByTarget(this, true));

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

        this.targetTasks.addTask(2, new EntityAINearestAttackableTarget(this, EntityVillager.class, 0, false));

        this.setSize(1.0F, 1.3F);

// TODO Auto-generated constructor stub

}

 

protected String getLivingSound(){

return "mob.wither.idle";

}

 

protected String getDeathSound(){

return "mob.wither.death";

}

 

protected String getHurtSound(){

    return "mob.wither.hurt";

}

 

protected void func_145780_a(int p_145780_1_, int p_145780_2_, int p_145780_3_, Block p_145780_4_)

    {

        this.playSound("mob.pig.step", 0.15F, 1.0F);

    }

 

protected Entity findPlayerToAttack(){

EntityPlayer entityPlayer = this.worldObj.getClosestVulnerablePlayerToEntity(this, 32.0D);

return entityPlayer != null && this.canEntityBeSeen(entityPlayer) ? entityPlayer : null;

 

}

 

 

public void applyEntityAttributes(){

super.applyEntityAttributes();

 

this.getEntityAttribute(SharedMonsterAttributes.attackDamage).setBaseValue(5.0D);

this.getEntityAttribute(SharedMonsterAttributes.followRange).setBaseValue(32.0D);

this.getEntityAttribute(SharedMonsterAttributes.knockbackResistance).setBaseValue(0.5D);

this.getEntityAttribute(SharedMonsterAttributes.movementSpeed).setBaseValue(0.44D);

this.getEntityAttribute(SharedMonsterAttributes.maxHealth).setBaseValue(35.0D);

}

 

protected void entityInit()

    {

        super.entityInit();

        this.getDataWatcher().addObject(12, Byte.valueOf((byte)0));

        this.getDataWatcher().addObject(13, Byte.valueOf((byte)0));

        this.getDataWatcher().addObject(14, Byte.valueOf((byte)0));

    }

 

 

@Override

public boolean attackEntityAsMob(Entity par1Entity) {

        super.attackEntityAsMob(par1Entity);

        if (this.entityToAttack != null) {

            this.entityToAttack.addVelocity(this.motionX * 2.0D, 2.0D, this.motionZ * 2.00D);

            if(this.entityToAttack instanceof EntityLiving) {

                ((EntityLiving)this.entityToAttack).addPotionEffect(new PotionEffect(Potion.moveSlowdown.id, 50, 0));

            }

            return true;

        }

        return false;

    }

 

@Override

protected boolean isAIEnabled() {

        return true;

    }

 

 

}

 

 

 

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.