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
comment_145599

Hey there.

 

So I have a block of code that consumes items in an ItemStack to use as ammunition.  It was working great until I moved the method to a new class and now it is all wonky.  The method is called on a right mouse click when the player is holding a certain item.  When the player right clicks, everything else happens that is supposed to happen (there are other actions as well), but the itemstack is not reduced at all.  When I right click, then exit the world and log back in, the itemstack is reduced!  I am so confused, does anyone have an answer to this?

 

Here is the method that deducts items from the itemstack (depending on how many items it should deduct):

//Consumes the correct amount of items from the stack
public static void consumeRunes(int consume, Item item) {
int i = 0;
while (consume > i) {
	caster.inventory.consumeInventoryItem(item);
	++i;
}
}

 

In this code, "caster" is a variable for the player that clicked.

 

 

UPDATE:

All of the items being consumed in this class only do so after logging out and then in again (even if it is just a single line calling caster.inventory.consumeInventoryItem(item) )

 

I have a class with a right_click listener that creates a new "spell" and then calls the "cast" method on it to cast the spell.

 

call within the listener:

if(!world.isRemote) {
Spell spellToCast = new Spell(currentSpell, player);
spellToCast.cast();

}

in the cast method (Where it says "OBF" I've obfuscated my code because I don't want to give away more details than I have to on a public forum ;P):

public static void cast() {
if (name.equalsIgnoreCase("OBF"))
	OBF();
}

 

method that actually acts on the itemstacks (again obfuscated):

public static void OBF() {
caster.inventory.consumeInventoryItem(OBF-ITEM);
}

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.