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

Hello everyone. I've got a little problem and some questions.

 

1.I want my mob to throw poison potions at me and melee attack me when i get close. I've looked at witch's code and i've made my mob throw potions at me. So that works, but when i use attackOnColide task on my mob, it only melee attacks me, not throwing potions. How to do so:

Throw potions at me when im far from mob, or mob cant get me( im on the roof or something in this sort ), and melee attack me when i get close to it.

 

Help me please, i really need this.

  • Author

You should take a look at the Witch, as it throws potions.

 

Check out my question again. I've made my mob throwing potions, but when i set task attackOnColide to him, it only perform melee attacks on me and not throwing potions. Without that task, my mob throws potions well. I want him to perform both attacks.

  • Author

Then remove the task when there is no player around.

 

What? How i suppose to do that? Please give the code if you know something about it.

  • Author

You should take a look at the Witch, as it throws potions.

 

So did you understand my question and can you help me please?

  • Author

So did you understand my question and can you help me please?

You need 2 AI tasks. One which throws the potions and one which performs the melee attack. The methods in the EntityAI class are pretty self explanatory to be honest.

 

this.tasks.addTask(0, new EntityAISwimming(this));
	this.tasks.addTask(1, new EntityAIWander(this, 0.2F));
	this.tasks.addTask(1, new EntityAIAttackOnCollide(this,
			EntityPlayer.class, this.moveSpeed, false));
	this.tasks.addTask(3, new EntityAIWatchClosest(this,
			EntityPlayer.class, 6.0F));
	this.tasks.addTask(4, new EntityAILookIdle(this));
	this.tasks.addTask(5, new EntityAIArrowAttack(this, this.moveSpeed, 60, 10.0F));

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

 

Those are my Entity tasks. I think ArrowAttack and AttackOnCollide perform both attacks. But ArrowAttack is not working with AttackOnCollide. So when i use AttackOnCollide, my Entity only perform melee attacks. So ArrowAttack is just confusing and stop working. Understand? But when i remove AttackOnCollide task, ArrowAttack works fine. But my mob cant perform melee attacks. Those tasks are not working with eachother. So i dont know what to do lol.

  • Author

You have to make your own task.

 

What?? Um and how i suppose to do that actually? This is so hard, hundreds of code.

  • Author

What?? Um and how i suppose to do that actually? This is so hard, hundreds of code.

Learn how to program. Sorry, modding without programming is impossible.

 

I know the basics of java. But i without copying stuff and reading from somewhere, thats impossible to draw a code by myself. All that symbols have to be correctly put.

Then remove the task when there is no player around.

 

What? How i suppose to do that? Please give the code if you know something about it.

See the line

task.addTask

?

Then this exist too

task.removeTask

 

Now, how to find a player ?

EntityPlayer closePlayer = this.worldObj.getClosestPlayerToEntity(this, putSomeDistanceHere);
if(closePlayer==null){
//forever alone
}else{
//kill the bastard
}

  • Author

Then remove the task when there is no player around.

 

What? How i suppose to do that? Please give the code if you know something about it.

See the line

task.addTask

?

Then this exist too

task.removeTask

 

Now, how to find a player ?

EntityPlayer closePlayer = this.worldObj.getClosestPlayerToEntity(this, putSomeDistanceHere);
if(closePlayer==null){
//forever alone
}else{
//kill the bastard
}

 

Ok, so i've made how you type and that works! So my mob shoots potion in me when he cant get me with himself. Thank you so much.

  • Author

Then remove the task when there is no player around.

 

What? How i suppose to do that? Please give the code if you know something about it.

See the line

task.addTask

?

Then this exist too

task.removeTask

 

Now, how to find a player ?

EntityPlayer closePlayer = this.worldObj.getClosestPlayerToEntity(this, putSomeDistanceHere);
if(closePlayer==null){
//forever alone
}else{
//kill the bastard
}

 

I think that exactly what you mean? Well it works. Sometimes he mess up a little though

EntityPlayer closePlayer = this.worldObj.getClosestPlayerToEntity(this, 4);
	if(closePlayer==null){
		EntityAIArrowAttack arrowattack = null;
		this.tasks.removeTask(arrowattack);
		this.tasks.addTask(3, new EntityAIAttackOnCollide(this,
				EntityPlayer.class, this.moveSpeed, false));

	}else
	{
		EntityAIAttackOnCollide attackoncollide = null;
		this.tasks.removeTask(attackoncollide);
	}
}

I think that exactly what you mean? Well it works. Sometimes he mess up a little though

EntityPlayer closePlayer = this.worldObj.getClosestPlayerToEntity(this, 4);
	if(closePlayer==null){
		EntityAIArrowAttack arrowattack = null;
		this.tasks.removeTask(arrowattack);
		this.tasks.addTask(3, new EntityAIAttackOnCollide(this,
				EntityPlayer.class, this.moveSpeed, false));

	}else
	{
		EntityAIAttackOnCollide attackoncollide = null;
		this.tasks.removeTask(attackoncollide);
	}
}

EntityAIAttackOnCollide attackoncollide = null;
		this.tasks.removeTask(attackoncollide);

This is really unlikely to work. You need to cache the task you want to change.

 

public EntityAIBase cache;

public void onUpdate{
  ...
EntityPlayer closePlayer = this.worldObj.getClosestPlayerToEntity(this, 4);
	if(closePlayer==null){
                       if(this.cache!=null){
		   this.tasks.removeTask(cache);
                           this.cache = null;
                      }
	}else if(this.cache ==null)
	{
	      this.cache = new EntityAIAttackOnCollide(this,
				EntityPlayer.class, this.moveSpeed, false);
              this.tasks.addTask(3, cache);
	}
}

 

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.