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

so as you guys probably know from previous posts, I am constantly trying to make an attack animation for my ranged mob. the problem is, Im not sure how to implement an attack timer for a ranged mob so, yeah can someone explain it to me please.

 

here is my current code:

package com.OlympiansMod.entity;

import com.OlympiansMod.Item.ModItems;

import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLiving;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.IRangedAttackMob;
import net.minecraft.entity.SharedMonsterAttributes;
import net.minecraft.entity.ai.EntityAIArrowAttack;
import net.minecraft.entity.ai.EntityAIAttackOnCollide;
import net.minecraft.entity.ai.EntityAIHurtByTarget;
import net.minecraft.entity.ai.EntityAILookIdle;
import net.minecraft.entity.ai.EntityAIMoveTowardsTarget;
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.boss.BossStatus;
import net.minecraft.entity.boss.IBossDisplayData;
import net.minecraft.entity.monster.EntityGolem;
import net.minecraft.entity.monster.EntityMob;
import net.minecraft.entity.monster.EntityWitch;
import net.minecraft.entity.monster.IMob;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.projectile.EntityPotion;
import net.minecraft.init.Items;
import net.minecraft.item.ItemStack;
import net.minecraft.potion.Potion;
import net.minecraft.util.DamageSource;
import net.minecraft.util.MathHelper;
import net.minecraft.world.World;

public class Zeus extends EntityGolem implements IBossDisplayData, IRangedAttackMob{  
 private EntityAIArrowAttack aiArrowAttack = new EntityAIArrowAttack(this, 1.0D, 20, 60, 15.0F);
 private EntityAIAttackOnCollide aiAttackOnCollide = new EntityAIAttackOnCollide(this, EntityPlayer.class, 1.2D, false);
private int attackTimer;

    private static final String __OBFID = "CL_00001697";


public Zeus(World world) { 
	super(world);
	 {
	   this.isImmuneToFire = true;
	   this.setHealth(this.getMaxHealth());
	   this.experienceValue = 10000;
	   this.setSize(1.1F, 2F);	  
	   this.getNavigator().setAvoidsWater(true);    
	   this.tasks.addTask(1, new EntityAISwimming(this));
	   this.tasks.addTask(2, new EntityAIWander(this, 0.5D));
	   this.tasks.addTask(3, new EntityAIWatchClosest(this, EntityPlayer.class, 1.0F));
	   this.tasks.addTask(3, new EntityAILookIdle(this));
	   this.tasks.addTask(5, new EntityAIMoveTowardsTarget(this, 0.7D, 100.0F));
	   this.targetTasks.addTask(1, new EntityAIHurtByTarget(this, true));
	   this.targetTasks.addTask(2, new EntityAINearestAttackableTarget(this, EntityPlayer.class, 0, true));
	   this.targetTasks.addTask(3, new EntityAINearestAttackableTarget(this, EntityLiving.class, 0, false, true, IMob.mobSelector));
	   
        
	   if (world != null && !world.isRemote)
        {
            this.setCombatTask();
        }
    }
	    } 
 public void onLivingUpdate()
 {
	super.onLivingUpdate();
  BossStatus.setBossStatus(this, true);

  if (!this.worldObj.isRemote)
  {
      if (this.getAggressive())
      {
         if (this.attackTimer-- <= 0)
        	 this.attackTimer = 1;
        	 
          {
  

 }
      }}
         
    


 }   	   

public boolean isAIEnabled(){

	return true;
}
@Override
protected void entityInit() {
	super.entityInit();
	dataWatcher.addObject(21, (byte) 0);
}


public void setAggressive(boolean par2)
    {
        this.getDataWatcher().updateObject(21, Byte.valueOf((byte)(par2 ? 1 : 0)));
    }

   
    public boolean getAggressive()
    {
        return this.getDataWatcher().getWatchableObjectByte(21) == 1;
    }
   // protected void addRandomArmor()
    //{
       // super.addRandomArmor();
        //this.setCurrentItemOrArmor(0, new ItemStack(ModItems.MasterBolt));
    //}

	    protected void applyEntityAttributes(){
	        super.applyEntityAttributes();
	        this.getEntityAttribute(SharedMonsterAttributes.followRange).setBaseValue(70.0D);
	        this.getEntityAttribute(SharedMonsterAttributes.maxHealth).setBaseValue(5000.0D);
	        this.getEntityAttribute(SharedMonsterAttributes.movementSpeed).setBaseValue(0.5D);
	       
	    }
	    
	    
	public void setCombatTask()
	 {
	   
	      {
	      this.tasks.addTask(4, this.aiArrowAttack);
	      }
	     
	      {
	      this.tasks.addTask(4, this.aiAttackOnCollide);
	      }
	 }
   


@Override 
   public void attackEntityWithRangedAttack(EntityLivingBase entity, float par1)
    {
        if (!this.getAggressive())
        {
        	
            EntityMasterBolt Bolt = new EntityMasterBolt(this.worldObj, this);
            Bolt.rotationPitch -= -20.0F;
            double d0 = entity.posX + entity.motionX - this.posX;
            double d1 = entity.posY + (double)entity.getEyeHeight() - 1.900000023841858D - this.posY;
            double d2 = entity.posZ + entity.motionZ - this.posZ;
            float f1 = MathHelper.sqrt_double(d0 * d0 + d2 * d2);

            
            Bolt.setThrowableHeading(d0, d1 + (double)(f1 * 0.2F), d2, 0.75F, 8.0F);
            this.worldObj.spawnEntityInWorld(Bolt);
        }
    } 

 @SideOnly(Side.CLIENT)
    public void handleHealthUpdate(byte p_70103_1_)
    
    {
        if (p_70103_1_ == 15)
        	
        {
        	 this.attackTimer = 1;
            for (int i = 0; i < this.rand.nextInt(35) + 10; ++i)
            {
                this.worldObj.spawnParticle("witchMagic", this.posX + this.rand.nextGaussian() * 0.12999999523162842D, this.boundingBox.maxY + 0.5D + this.rand.nextGaussian() * 0.12999999523162842D, this.posZ + this.rand.nextGaussian() * 0.12999999523162842D, 0.0D, 0.0D, 0.0D);
            }
        }
        else
        {
            super.handleHealthUpdate(p_70103_1_);
        }
    }	
       
        @SideOnly(Side.CLIENT)
        public int  getattackTimer()
        {
            return this.attackTimer;

        }
         
protected void dropFewItems(boolean par1, int par2)
{
    this.dropItem(ModItems.MasterBolt, 1);

}
}


        










 

 

thanks

Im serious don't look at it!!

also how to you call on the entitys health when they get to a certain health.

What?

 

I think he means to ask "how to execute something when Entity has certain HP". Again, onUpdate() is your friend.

If my post helped you, please press that "Thank You"-button to show your appreciation.

 

Also if you don't know Java, I would suggest you read the official tutorials by Oracle to get an idea of how to do this. Thanks, and good modding!

 

Also if you haven't, set up a Git repo for your mod not only for convinience but also to make it easier to help you.

And getHealth()

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.

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.