Jump to content

[1.7.10] item consume not happening until after logout?


ArtisanGaming

Recommended Posts

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);
}

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.