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

Hi, i got a problem. Maybe first the code:

 

public class ItemBandage extends Item {

public ItemBandage(int par1) {
	super(par1); //par1 is ID
	setCreativeTab(CreativeTabs.tabMisc);
	}

public ItemStack onItemRightClick(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer) {
	if (hamrInjurys.brokenFootBoolean==true){
		--par1ItemStack.stackSize;
		hamrInjurys.brokenFootBoolean = false;
	}

	return par1ItemStack;
	}

}

 

brokenFootBoolean gets true once a certain potion of mine is activated. That is working.

So when rightclicked, --par1ItemStack.stackSize makes sure it gets removed from my inventory (it cant be stacked) And then setting brokenFootBoolean is for something else.

 

So then, the spot where the bandage was is empty. But if i rightclick again once or twice, the item returns. You could see that as eating your food, right clicking with your hand in the air, and getting it back. How can i fix that?

 

Edit, main class (RS_HAMR) :

 

In class itself:

public static Item bandage;

 

In @init :

bandage = new ItemBandage(7000).setUnlocalizedName("bandage").setMaxStackSize(1);
                LanguageRegistry.addName(bandage, "Bandage");

 

 

EDIT 2: Seems you only get it back when you rightclick a block, not the air.

Use

par3EntityPlayer.inventoryContainer.detectAndSendChanges();

after you decrease your itemstack. May help.

If i helped you, don't forget pressing "Thank You" button. Thanks for your time.

  • Author

Use

par3EntityPlayer.inventoryContainer.detectAndSendChanges();

after you decrease your itemstack. May help.

 

You mean like this? :

 

public ItemStack onItemRightClick(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer) {
	if (hamrInjurys.brokenFootBoolean==true){
		--par1ItemStack.stackSize;
		par3EntityPlayer.inventoryContainer.detectAndSendChanges();
		hamrInjurys.brokenFootBoolean = false;
	}

	return par1ItemStack;
	}

 

 

Sorry, but it didnt chance anything in-game. The problem still happens.

Hmmm... That code actually worked for me when in classic mode, but not in creative... Don't know then. Sorry.

If i helped you, don't forget pressing "Thank You" button. Thanks for your time.

The returned ItemStack is what you are left holding after the method is processed. To decrement a stack, just use ItemStack.stackSize-- and return the new stack (checking for if the new size is zero and nulling if necessary). To remove it entirely, return null.

player.inventory.setInventorySlotContents(slot, null);

but you need to iterate throught the players inventory to get the slot.

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.