Jump to content

Recommended Posts

Posted

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

Posted

Your AI class should have a method called shouldExecute(). You can check the conditions you want there to prevent it from executing if you don't want it to. There is also a method called continueExecuting() where you can check to see if there is any condition met for stopping the AI.

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

Posted

I tried passing a boolean in my onItemUse method to my shouldExecute but it didnt read. I want it to execute when i right click on an item. Is that possible?

Posted

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/

Posted

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

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

Posted

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/

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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Hello I'm currently making an Item that thrusts you to viewing direction, and I referenced riptide code of trident for my item. @Override public InteractionResultHolder<ItemStack> use(Level pLevel, Player pPlayer, InteractionHand pUsedHand) { if(!pLevel.isClientSide() && pUsedHand == InteractionHand.MAIN_HAND && pPlayer.isOnGround()){ Impale(pPlayer, pUsedHand); pPlayer.getCooldowns().addCooldown(this, 40); } return super.use(pLevel, pPlayer, pUsedHand); } public void Impale(Player pPlayer, InteractionHand pUsedHand) { float playerYRot = pPlayer.getYRot(); float xForce = -Mth.sin(playerYRot * ((float)Math.PI / 180F)) * Mth.cos((float)Math.PI / 180F); float yForce = 100.6F; float zForce = Mth.cos(playerYRot * ((float)Math.PI / 180F)) * Mth.cos((float)Math.PI / 180F); float stabilizedForce = Mth.sqrt(xForce * xForce + zForce * zForce); xForce /= stabilizedForce; zForce /= stabilizedForce; pPlayer.push((double)xForce, (double)yForce, (double)zForce); pPlayer.sendSystemMessage(Component.literal(playerYRot + " " + xForce + " " + yForce + " " + zForce + " " + stabilizedForce + "shoo")); } I sure edited a lot from source code but this isn't working somehow? the sendSystemMessage works correctly. It prints value of variables and string, but the force isn't applying to player. how can I make this to work? Thanks.
    • i tried putting a modpack together and cant get this working no matter what i have tried log: https://pastebin.com/uqz1aKiY
    • We have an event for an Entity being struck by lighting, but doesn't look like we have one for Blocks. And unfortunately, looking at it, the LightingBolt entity doesn't have any context on why it was registered, so you wouldn't be able to get the source context. What are you trying to accomplish with this event?
    • Hey guys, I'm trying to use the simple planes mod https://www.curseforge.com/minecraft/mc-mods/simple-planes with a nuclear bombs mod https://www.curseforge.com/minecraft/mc-mods/nuclear-bombs . The simple planes mod has a cargo plane that can drop tnt, and i want it to work with the nuclear bombs. I added this JSON file from chatGPT to the payloads folder in simple planes (because the nukes couldn't even get stored in the plane in the first place), but this only allows the nuke to drop but doesn't explode: https://mclo.gs/3uEQIX2 . This nuke mod requires a redstone signal and then manual activation, which makes this tougher i imagine. If someone could write me a code for the payload folder for simpleplanes, something that even tampers with the nuke mod, or any general suggestions that would be great!  Many Thanks
    • https://paste.ee/p/Qai73Cbt  that is crash file link  
  • Topics

×
×
  • Create New...

Important Information

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