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

I want my mob to have a ranged attack and then it will have a cooldown and during the cooldown I want the champion to do melee attacks, I did the Iprojectile and I tried adding both tasks to see if it will just do it but it starts melee one spawned and then it decides to go ranged and stay ranged.

 

package leagueofcrafters.entity;

import leagueofcrafters.entity.projectiles.EntityPukeball;
import net.minecraft.entity.Entity;
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.EntityAIBreakDoor;
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.util.MathHelper;
import net.minecraft.world.World;

public class EntityNuNu extends EntityMob implements IRangedAttackMob {

private static int timer;

public EntityNuNu(World par1World) {
	super(par1World);
	this.tasks.addTask(0, new EntityAISwimming(this));
	this.tasks.addTask(1, new EntityAIBreakDoor(this));
	this.tasks.addTask(2, new EntityAIAttackOnCollide(this, EntityPlayer.class, 1.0D, false));
	this.tasks.addTask(3, new EntityAIAttackOnCollide(this, EntityVillager.class, 1.0D, true));
	this.tasks.addTask(4, new EntityAIMoveTowardsRestriction(this, 1.0D));
	this.tasks.addTask(5, new EntityAIMoveThroughVillage(this, 1.0D, false));
	this.tasks.addTask(6, new EntityAIWander(this, 1.0D));
	this.tasks.addTask(7, new EntityAIWatchClosest(this, EntityPlayer.class, 8.0F));
	this.tasks.addTask(7, new EntityAILookIdle(this));
	this.tasks.addTask(2, new EntityAIArrowAttack(this, 1.0D, 60, 10.0F));
	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));

}

@Override
public boolean isAIEnabled() {
	return true;
}

@Override
protected Entity findPlayerToAttack() {
	double d0 = 16.0D;
	return this.worldObj.getClosestVulnerablePlayerToEntity(this, d0);
}

@Override
public void onLivingUpdate() {
	if (!this.worldObj.isRemote && this.timer > 0) {
		timer--;
	}
	super.onLivingUpdate();
}

@Override
protected void applyEntityAttributes() {
	super.applyEntityAttributes();
	this.getEntityAttribute(SharedMonsterAttributes.movementSpeed).setAttribute(0.2D);
}

@Override
public void attackEntityWithRangedAttack(EntityLivingBase entitylivingbase, float f) {
	if (timer == 0) {
		EntityPukeball entityPukeball = new EntityPukeball(this.worldObj, this);
		double d0 = entitylivingbase.posX - this.posX;
		double d1 = entitylivingbase.posY + (double) entitylivingbase.getEyeHeight() - entityPukeball.posY - 2;
		double d2 = entitylivingbase.posZ - this.posZ;
		float f1 = MathHelper.sqrt_double(d0 * d0 + d2 * d2) * 0.2F;
		entityPukeball.setThrowableHeading(d0, d1 + (double) f1, d2, 1.6F, 12.0F);
		this.worldObj.spawnEntityInWorld(entityPukeball);
		timer = 250;

	} else {
		this.targetTasks.addTask(4, new EntityAINearestAttackableTarget(this, EntityPlayer.class, 0, true));
		 this.attackEntity(entitylivingbase, f);
		 this.attackEntityAsMob(entitylivingbase);
	}
}

protected void attackEntity(Entity par1Entity, float par2) {
	float f1 = this.getBrightness(1.0F);

	if (f1 > 0.5F && this.rand.nextInt(100) == 0) {
		this.entityToAttack = null;
	} else {
		if (par2 > 2.0F && par2 < 6.0F && this.rand.nextInt(10) == 0) {
			if (this.onGround) {
				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 * 0.5D * 0.800000011920929D + this.motionX * 0.20000000298023224D;
				this.motionZ = d1 / (double) f2 * 0.5D * 0.800000011920929D + this.motionZ * 0.20000000298023224D;
				this.motionY = 0.4000000059604645D;
			}
		} else {
			super.attackEntity(par1Entity, par2);
		}
	}
}
}

I have not attempted doing what your trying before, but i know you can add and remove tasks at any point in the Entities code. so you could remove the EntityAIArrowAttack task when it shoots and arrow, then after the cooldown readd it.

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.