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

Lets go to forward the main. Here is the code of my mob:

 

 

package halflifemod.entity.monster;

 

import halflifemod.client.model.ModelGonome;

import halflifemod.client.model.ModelHeadcrab;

import halflifemod.main.EntityFollowable;

import halflifemod.main.mod_HalflifeMod;

 

import org.lwjgl.opengl.GL11;

 

import cpw.mods.fml.relauncher.Side;

import cpw.mods.fml.relauncher.SideOnly;

import net.minecraft.entity.Entity;

import net.minecraft.entity.EnumCreatureAttribute;

import net.minecraft.entity.ai.EntityAIAttackOnCollide;

import net.minecraft.entity.ai.EntityAIHurtByTarget;

import net.minecraft.entity.ai.EntityAILookIdle;

import net.minecraft.entity.ai.EntityAINearestAttackableTarget;

import net.minecraft.entity.ai.EntityAISwimming;

import net.minecraft.entity.ai.EntityAIWatchClosest;

import net.minecraft.entity.monster.EntityMob;

import net.minecraft.entity.monster.EntitySlime;

import net.minecraft.entity.player.EntityPlayer;

import net.minecraft.item.Item;

import net.minecraft.potion.Potion;

import net.minecraft.potion.PotionEffect;

import net.minecraft.util.DamageSource;

import net.minecraft.util.MathHelper;

import net.minecraft.world.World;

 

public class EntityHeadcrab extends EntityMob

{

private int attackTimer = 0;

    public EntityHeadcrab(World par1World)

    {

        super(par1World);

        this.texture = "/mob/HL/Headcrab.png";

        this.setSize(0.6F, 0.4F);

        this.moveSpeed = 0.23F;

        this.getNavigator().setAvoidsWater(true);

        this.targetTasks.addTask(1, new EntityAINearestAttackableTarget(this,EntityFollowable.class, 25.0F, 0, true));

    }

 

    protected void entityInit()

    {

        super.entityInit();

        this.dataWatcher.addObject(16, new Byte((byte)0));

    }

 

 

    public int getMaxHealth()

    {

        return 8;

    }

 

   

    protected int getAttackStrength()

    {

        return 0;

    }

   

    protected boolean canDamagePlayer()

    {

        return true;

    }

 

    protected Entity findPlayerToAttack()

    {

            double d0 = 10.0D;

            return this.worldObj.getClosestVulnerablePlayerToEntity(this, d0);

    }

 

    public boolean attackEntityAsMob(Entity par1Entity)

    {

    if(!this.onGround)

    {

        boolean flag = par1Entity.attackEntityFrom(DamageSource.causeMobDamage(this), 4);

        this.playSound("headcrab.hc_headbite", 0.5F, 1.0F);

        return flag;

    }

return super.attackEntityAsMob(par1Entity);   

    }

 

    protected String getLivingSound()

    {

        return "headcrab.hc_say";

    }

 

    protected String getHurtSound()

    {

        return "headcrab.hc_hurt";

    }

 

    protected String getDeathSound()

    {

        return "headcrab.hc_die";

    }

   

    protected void attackEntity(Entity par1Entity, float par2)

    {

            if (par2 > 2.0F && par2 < 6.0F && this.rand.nextInt(10) == 0)

            { 

                if (this.onGround)

                {

                this.attackTimer++;

                if(this.attackTimer > 3)

                {

                    double d0 = par1Entity.posX - this.posX;

                    double d1 = par1Entity.posZ - this.posZ;

                    float f2 = MathHelper.sqrt_double(d0 * d0 + d1 * d1);

                    this.motionX = d0 / (double)f2 * 1.2D * 0.800000011920929D + this.motionX * 0.20000000298023224D;

                    this.motionZ = d1 / (double)f2 * 1.2D * 0.800000011920929D + this.motionZ * 0.20000000298023224D;

                    this.motionY = 0.5600000059604645D;

                    this.playSound("headcrab.hc_attack", 1.0F, 1.0F);

                    this.attackTimer = 0;

                }

                }

            }

            else

            {

                super.attackEntity(par1Entity, par2);

            }         

        }

   

 

    @SideOnly(Side.CLIENT)

    public int getAttackTimer()

    {

        return this.attackTimer;

    }

   

    protected void dropFewItems(boolean par1, int par2)

    {

        super.dropFewItems(par1, par2);

 

        int j = this.rand.nextInt(3) + this.rand.nextInt(1 + par2);

        int k;

 

        for (k = 0; k < j; ++k)

        {

            this.dropItem(mod_HalflifeMod.headcrabSting.itemID, 1);

        }

    }

   

    public EnumCreatureAttribute getCreatureAttribute()

    {

        return EnumCreatureAttribute.ARTHROPOD;

    }

 

    public boolean isPotionApplicable(PotionEffect par1PotionEffect)

    {

        return par1PotionEffect.getPotionID() == Potion.poison.id ? true : super.isPotionApplicable(par1PotionEffect);

    }

}

 

 

 

 

So, there is actually his AI too. But when i put this:

protected boolean isAIEnabled()// enable/disable ai
{
	return true;
}

 

All of the code stop working. So mob doesnt attack as it was before i put isAIEnabled = true. How can  i fix this? Really need your help.

  • Author

You can either use the new ai (isAIEnabled = true) or don't use it. If you use it, your attack code must be done with AI-Tasks as well.

 

How can i use all attack code i have in the task? Please help.

  • Author

It will not work with copy and pasting. You have to actually understand the code and then adapt it for the tasks.

 

Well, this AI doesnt even take my variables. It used to be an Entity, not EntityAIMyai. I dont really know how can i wrap up the code and left it the same...

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.