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

Here are my ai classes OwnerHurtbyTarget and OwnerHurtTarget i dont know why he is not defending me when he is tamed just runs away xD help pls

 

 

 

OwnerHurtbyTarget

 

package com.medamobs.AI;

 

import java.util.Iterator;

import java.util.List;

 

import net.minecraft.entity.EntityCreature;

import net.minecraft.entity.EntityLivingBase;

import net.minecraft.entity.ai.EntityAITarget;

import net.minecraft.util.AxisAlignedBB;

 

import com.medamobs.entities.MedabotBase;

 

public class MedamobsEntityAIOwnerHurtByTarget extends EntityAITarget

{

    MedabotBase theDefendingTameable;

    EntityLivingBase theOwnerAttacker;

    private int field_142051_e;

private int field_142052_b;

private boolean entityCallsForHelp;

 

    public MedamobsEntityAIOwnerHurtByTarget(MedabotBase par1EntityTameable)

    {

        super(par1EntityTameable, false);

        this.theDefendingTameable = par1EntityTameable;

        this.setMutexBits(1);

    }

 

    /**

    * Returns whether the EntityAIBase should begin execution.

    */

    public boolean shouldExecute()

    {

        int i = this.taskOwner.func_142015_aE();

        return i != this.field_142052_b && this.isSuitableTarget(this.taskOwner.getAITarget(), false);

    }

 

    /**

    * Execute a one shot task or start executing a continuous task

    */

    public void startExecuting()

    {

        this.taskOwner.setAttackTarget(this.taskOwner.getAITarget());

        this.field_142052_b = this.taskOwner.func_142015_aE();

 

        if (this.entityCallsForHelp)

        {

            double d0 = this.getTargetDistance();

            List list = this.taskOwner.worldObj.getEntitiesWithinAABB(this.taskOwner.getClass(), AxisAlignedBB.getBoundingBox(this.taskOwner.posX, this.taskOwner.posY, this.taskOwner.posZ, this.taskOwner.posX + 1.0D, this.taskOwner.posY + 1.0D, this.taskOwner.posZ + 1.0D).expand(d0, 10.0D, d0));

            Iterator iterator = list.iterator();

 

            while (iterator.hasNext())

            {

                EntityCreature entitycreature = (EntityCreature)iterator.next();

 

                if (this.taskOwner != entitycreature && entitycreature.getAttackTarget() == null && !entitycreature.isOnSameTeam(this.taskOwner.getAITarget()))

                {

                    entitycreature.setAttackTarget(this.taskOwner.getAITarget());

                }

            }

        }

 

        super.startExecuting();

    }

}

 

 

 

OwnerHurtTarget

 

package com.medamobs.AI;

 

import java.util.Iterator;

import java.util.List;

 

import net.minecraft.entity.EntityCreature;

import net.minecraft.entity.EntityLivingBase;

import net.minecraft.entity.ai.EntityAITarget;

import net.minecraft.util.AxisAlignedBB;

 

import com.medamobs.entities.MedabotBase;

 

public class MedamobsEntityAIOwnerHurtTarget extends EntityAITarget

{

MedabotBase theEntityTameable;

    EntityLivingBase theTarget;

    private int field_142050_e;

private boolean entityCallsForHelp;

private int field_142052_b;

 

    public MedamobsEntityAIOwnerHurtTarget(MedabotBase par1EntityTameable)

    {

        super(par1EntityTameable, false);

        this.theEntityTameable = par1EntityTameable;

        this.setMutexBits(1);

    }

 

    /**

    * Returns whether the EntityAIBase should begin execution.

    */

    public boolean shouldExecute()

    {

        if (!this.theEntityTameable.isTamed())

        {

            return false;

        }

        else

        {

            EntityLivingBase entitylivingbase = this.theEntityTameable.func_130012_q();

 

            if (entitylivingbase == null)

            {

                return false;

            }

            else

            {

                this.theTarget = entitylivingbase.getLastAttacker();

                int i = entitylivingbase.getLastAttackerTime();

                return i != this.field_142050_e && this.isSuitableTarget(this.theTarget, false) && this.theEntityTameable.func_142018_a(this.theTarget, entitylivingbase);

            }

        }

    }

 

    /**

    * Execute a one shot task or start executing a continuous task

    */

    public void startExecuting()

    {

        this.taskOwner.setAttackTarget(this.taskOwner.getAITarget());

        this.field_142052_b = this.taskOwner.func_142015_aE();

 

        if (this.entityCallsForHelp)

        {

            double d0 = this.getTargetDistance();

            List list = this.taskOwner.worldObj.getEntitiesWithinAABB(this.taskOwner.getClass(), AxisAlignedBB.getBoundingBox(this.taskOwner.posX, this.taskOwner.posY, this.taskOwner.posZ, this.taskOwner.posX + 1.0D, this.taskOwner.posY + 1.0D, this.taskOwner.posZ + 1.0D).expand(d0, 10.0D, d0));

            Iterator iterator = list.iterator();

 

            while (iterator.hasNext())

            {

                EntityCreature entitycreature = (EntityCreature)iterator.next();

 

                if (this.taskOwner != entitycreature && entitycreature.getAttackTarget() == null && !entitycreature.isOnSameTeam(this.taskOwner.getAITarget()))

                {

                    entitycreature.setAttackTarget(this.taskOwner.getAITarget());

                }

            }

        }

 

        super.startExecuting();

    }

}

 

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.