Jump to content

[SOLVED]Enabling/Disabling Custom Task for Custom AI


najib333

Recommended Posts

Hello guys,

 

Is there really a way to enable or disable certain task using items or right clicks on blocks? Im working on a MOD that uses an item to actually move my custom AI forward, sideways or backwards. Ive managed to create a class that extends EntityAIBase and is working fine. I just want to know is it possible for me to add or remove the task to my custom AI ingame by using custom items?

 

Lets say my AI is idle, when i use an item, the ai will move 5 blocks to the front, back, right or left, either one. This is what i want.

 

Cheers

Link to comment
Share on other sites

You need to make a boolean field in your entity as well. Then in the interact() method of your entity, check the type of item being held by the player. If it is the right item, then set the field in your entity.

 

Your AI task should have access to the entity, and so it can then look up the field value since you copied it to the entity in the interact() method.

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Link to comment
Share on other sites

Thanks for ur reply.

 

I just want to know how do i check for the itemstack im currently holding. I know that we need to use the player.inventory.getCurrentItem(); I want to check for my custom item. The method returns an ItemStack. How do i check if the player is holding my Custom Item?

 

Thanks

Link to comment
Share on other sites

The method returns an ItemStack.

 

The fuck do you think an ItemStack is?

It's a stack of items.

Look at its gorram fields and methods.

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.

Link to comment
Share on other sites

Thanks for ur reply.

 

I just want to know how do i check for the itemstack im currently holding. I know that we need to use the player.inventory.getCurrentItem(); I want to check for my custom item. The method returns an ItemStack. How do i check if the player is holding my Custom Item?

 

Thanks

 

As Draco says, look at the type hierarchy for ItemStack and familiarize yourself with all the methods available.

 

Anyway, there is a getItem() method for the ItemStack that you should compare to see if it is equal to the instance of your custom item.

 

 

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Link to comment
Share on other sites

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...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.