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.

How can I make it so an item is only used when it is in the Inventory Hotbar?

Featured Replies

Posted

Hello everybody,

I have a question. How can I make it so an item only works while it is in the Hotbar? For example; I have a staff that heals me by half a heart every 5 seconds and takes durability from it. But in order for the staff to do this, it has to be in the item hotbar. I am using Eclipse. I know this is possible because the same thing is done in Equivalent Exchange. You have a flying ring and it lets you fly, but only when it is in you item hotbar. So I basically need to add a new method but I don't know how... If it isn't possible to make it so only if the item is in the hotbar it works, then it still should be possible to make it work when it is in a certain slot. Then I select all the hotbar slots and then I have the hotbar. Any help?

Thanks.

Simply have a TickHandler check the player inventory at the hotbar's slot id's and if one of them is your item, apply the desired effect.

  • Author

Simply have a TickHandler check the player inventory at the hotbar's slot id's and if one of them is your item, apply the desired effect.

And how do I do that?

ITickHandler and the check slots 0-8 of the player(Hotbar)and see if they have it

The Korecraft Mod

  • Author

ITickHandler and the check slots 0-8 of the player(Hotbar)and see if they have it

I get that, but what line of code do I need to fill in? ITickHandler.?????? and where? In public void load? Because I'm not editing my base classes.

  • Author

Can't I do something like this?:

if (par1ItemStack.getInventorySlotContainItem() < 8)

for (int i = 0; i < 40; i++)

{

i = 0;

EntityPlayer entityPlayer = (EntityPlayer)par3Entity;

entityPlayer.heal(1);

par1ItemStack.damageItem(1, entityPlayer);

}

i found another way, yes you can do that, just create a void called

  public void onUpdate(ItemStack par1ItemStack, World par2World, Entity par3Entity, int par4, boolean par5) {}

the put that. (must be in the items class)

  • Author

Something like this?:

 

@Override

public void onUpdate(ItemStack par1ItemStack, World par2World, Entity par3Entity, int par4, boolean par5)

{

super.onUpdate(par1ItemStack, par2World, par3Entity, par4, par5);

 

EntityPlayer player = (EntityPlayer) par3Entity;

if(player.getHealth() < player.getMaxHealth())

{

for(int i=0;i<9;i++)

{

if(player.inventory.getStackInSlot(i) == par1ItemStack)

{

player.heal(1);

break;

}

}

}

}

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.