Jump to content

[1.6.2] Passive mob attack player?


kmccmk9

Recommended Posts

Hello, I'm trying to basically do what the title says. I have a passive mob which extends entityliving, and I would like it to attack the player if the player attacks it. I tried taking some code from both the cow and the wolf to try and implement this. Below, is what I have. Currently, it does not attack at all. Also for some reason the movement of my mob in general is very glitchy and random. Any help would be appreciated.

 

package kmccmk9.witchcraft;

import net.minecraft.client.renderer.EntityRenderer;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityCreature;
import net.minecraft.entity.EntityLiving;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.ai.EntityAIAttackOnCollide;
import net.minecraft.entity.ai.EntityAIBeg;
import net.minecraft.entity.ai.EntityAIFollowOwner;
import net.minecraft.entity.ai.EntityAIHurtByTarget;
import net.minecraft.entity.ai.EntityAILeapAtTarget;
import net.minecraft.entity.ai.EntityAILookIdle;
import net.minecraft.entity.ai.EntityAIMate;
import net.minecraft.entity.ai.EntityAIOwnerHurtByTarget;
import net.minecraft.entity.ai.EntityAIOwnerHurtTarget;
import net.minecraft.entity.ai.EntityAISwimming;
import net.minecraft.entity.ai.EntityAITargetNonTamed;
import net.minecraft.entity.ai.EntityAIWander;
import net.minecraft.entity.ai.EntityAIWatchClosest;
import net.minecraft.entity.passive.EntitySheep;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.util.DamageSource;
import net.minecraft.world.World;
import net.minecraft.src.*;

public class EntityBee extends EntityLiving {

public EntityBee(World par1World) {
	super(par1World);
	this.getNavigator().setAvoidsWater(true);
	this.setSize(0.5F, 0.5F);
	this.setEntityHealth(25F);
	this.setAIMoveSpeed(2F);
	this.tasks.addTask(0, new EntityAILookIdle(this));
	this.tasks.addTask(1, new EntityAISwimming(this));
        this.tasks.addTask(2, new EntityAILeapAtTarget(this, 0.4F));
        this.tasks.addTask(3, new EntityAIWatchClosest(this, EntityPlayer.class, 8.0F));
        this.tasks.addTask(4, new EntityAILookIdle(this));
}

protected int getDropItemId()
    {
        return Item.porkRaw.itemID;
    }

 /**
     * Returns true if the newer Entity AI code should be run
     */
    public boolean isAIEnabled()
    {
        return true;
    }

    /**
     * Sets the active target the Task system uses for tracking
     */
    public void setAttackTarget(EntityLivingBase par1EntityLivingBase)
    {
        super.setAttackTarget(par1EntityLivingBase);
    }
    
    public boolean attackEntityAsMob(Entity par1Entity)
    {
        int i = 7;
        return par1Entity.attackEntityFrom(DamageSource.causeMobDamage(this), (float)i);
    }
}

Link to comment
Share on other sites

couldn't you just extend entity creature instead and see how pig zombies do it?

 

actually

looking at the code for wolves it seems they basically do it in the same way

any reference to anger or an anger level is what you're looking for

they make it so that the mob is peaceful but when it gets attacked it gets angry and when it's angry it attacks

 

and the EntityAIHurtByTarget is in the wolf entity file so you should be fine adding it

but you will probably need to extend something other than EntityLiving, namely EntityCreature

 

wolves extend EntityTameable, which extends EntityAnimal, which extends EntityAgeable which extends EntityCreature, so extending EntityCreature may work better for you

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.