ArtisanGaming Posted February 25, 2015 Posted February 25, 2015 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); } Quote
Failender Posted February 25, 2015 Posted February 25, 2015 If you want to consume the item you should at one point check if the !world.isRemote Otherway it might happen that ure only triing to consume on the client side. Which is not necessary because the client gets told by the server Quote
ArtisanGaming Posted February 25, 2015 Author Posted February 25, 2015 I've already tried checking for that, it still doesnt make a difference Quote
ArtisanGaming Posted February 25, 2015 Author Posted February 25, 2015 It might help to let you guys know that it waits until the inventory items are updated to show the change. I don't actually have to log out I just have to pick the item up and the stack size is updated. Quote
Abastro Posted February 25, 2015 Posted February 25, 2015 1. Are you testing on Creative mode? 2. You should call markdirty method when you changes an inventory. Quote I. Stellarium for Minecraft: Configurable Universe for Minecraft! (WIP) II. Stellar Sky, Better Star Rendering&Sky Utility mod, had separated from Stellarium.
Recommended Posts
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.