I have yet another small issue I can't quite figure out. Basically my setup is that the player has an item, and they can use that item via right-click. When the item is used, the player's inventory is checked to see if it contains a special powder item. Assuming the item is found, one of the items is consumed (ie if they had a stack of 32, they now have a stack of 31) and it generates an effect in the world.
All of this is working completely flawlessly, even the decreasing of items from the player's inventory. The issue however is that the number of items the player sees does not update until they either move the stack to a new inventory slot, or relog into the world.
The code I'm using to lower the amount of items is this (player is an EntityPlayer, "charlotteUtilities" is my modID, and "powderColoured" is the item name):
Like I said, behind-the-scenes it is working fine - which leads me to believe it's something to do with server/client syncing (currently the method this is called within is NOT labled with @SideOnly(x), so it runs on both). I've tried running it on only the server side, and only the client side, but both cause angry Minecraft demons to spawn and destroy all that I have built.
Any idea on what needs to be done to get the player's inventory display to update whenever that code is ran?
Rollback Post to RevisionRollBack
Like to build? Check out Charlotte's Utilities - Layout Blocks, Brushes, Prospectors, and more!
Follow me on twitter @charlotte_c_b for updates! You can also find me in irc.esper.net as Ilandria
Development of my mods is made possible by Full Effect Hosting
Sounds the way you are updating the player's inventory is not correct by using player.inventory.decrStackSize(i,1);
There's probably another method that'll accomplish what you want that isn't so low level. Either that or your reference to the player variable is not the correct one (i.e. using Minecraft.thePlayer for a multiplayer mod)
Sounds the way you are updating the player's inventory is not correct by using player.inventory.decrStackSize(i,1);
There's probably another method that'll accomplish what you want that isn't so low level. Either that or your reference to the player variable is not the correct one (i.e. using Minecraft.thePlayer for a multiplayer mod)
The player reference I'm using is the EntityPlayer object that gets passed into the "onItemUse(ItemStack, EntityPlayer, etc...)" method in the Item class. I'm thinking there probably is another method, my issue is just that I'm new enough to Minecraft/Forge modding that I don't really know where else to look for one past where I already have (in EntityPlayer and parent classes).
Like I said, the way I'm doing it IS working - just it doesn't visually update till moving the item in your inventory or relogging.
Like to build? Check out Charlotte's Utilities - Layout Blocks, Brushes, Prospectors, and more!
Follow me on twitter @charlotte_c_b for updates! You can also find me in irc.esper.net as Ilandria
Development of my mods is made possible by Full Effect Hosting
You can change the stack size of the stack directly, since it refers to the same stack that is in the inventory. This is how I do it when the vanilla InventoryPlayer.consumeInventoryItem(int id) is not sufficient for my needs:
// after getting the ItemStack in slot [ i ]
--stack.stackSize;
if (stack.stackSize == 0) {
player.inventory.setInventorySlotContents(i, null);
}
That's basically exactly how the vanilla method works
// after getting the ItemStack in slot [ i ]
--stack.stackSize;
if (stack.stackSize == 0) {
player.inventory.setInventorySlotContents(i, null);
}
I implemented that and I'm having the exact same thing happen, where it changes behind-the-scenes but doesn't update the display until moving the items or relogging... I could post the entire class file here but it's getting a bit large at this point (like 350-400 lines) and I don't really want to make anyone read through everything. lol
I'll try to pick out just the functions that are related and post them all if you'd like, I really don't know what I'm doing wrong if this method works fine for you.
Like to build? Check out Charlotte's Utilities - Layout Blocks, Brushes, Prospectors, and more!
Follow me on twitter @charlotte_c_b for updates! You can also find me in irc.esper.net as Ilandria
Development of my mods is made possible by Full Effect Hosting
I've figured it out, I had to re-write about half of my class' coding cause I wasn't handling stuff between onItemUse and onUpdate properly.
Oh the woes of learning to work with an API, lol :3
Rollback Post to RevisionRollBack
Like to build? Check out Charlotte's Utilities - Layout Blocks, Brushes, Prospectors, and more!
Follow me on twitter @charlotte_c_b for updates! You can also find me in irc.esper.net as Ilandria
Development of my mods is made possible by Full Effect Hosting
Hi Sharshar. Would you be able to post a summary of what you had to change to fix this? I and a couple of others I've seen are having the same problem and so far nobody's posted a solution that works.
I have yet another small issue I can't quite figure out. Basically my setup is that the player has an item, and they can use that item via right-click. When the item is used, the player's inventory is checked to see if it contains a special powder item. Assuming the item is found, one of the items is consumed (ie if they had a stack of 32, they now have a stack of 31) and it generates an effect in the world.
All of this is working completely flawlessly, even the decreasing of items from the player's inventory. The issue however is that the number of items the player sees does not update until they either move the stack to a new inventory slot, or relog into the world.
The code I'm using to lower the amount of items is this (player is an EntityPlayer, "charlotteUtilities" is my modID, and "powderColoured" is the item name):
Like I said, behind-the-scenes it is working fine - which leads me to believe it's something to do with server/client syncing (currently the method this is called within is NOT labled with @SideOnly(x), so it runs on both). I've tried running it on only the server side, and only the client side, but both cause angry Minecraft demons to spawn and destroy all that I have built.
Any idea on what needs to be done to get the player's inventory display to update whenever that code is ran?
Follow me on twitter @charlotte_c_b for updates! You can also find me in irc.esper.net as Ilandria
Development of my mods is made possible by Full Effect Hosting
There's probably another method that'll accomplish what you want that isn't so low level. Either that or your reference to the player variable is not the correct one (i.e. using Minecraft.thePlayer for a multiplayer mod)
The player reference I'm using is the EntityPlayer object that gets passed into the "onItemUse(ItemStack, EntityPlayer, etc...)" method in the Item class. I'm thinking there probably is another method, my issue is just that I'm new enough to Minecraft/Forge modding that I don't really know where else to look for one past where I already have (in EntityPlayer and parent classes).
Like I said, the way I'm doing it IS working - just it doesn't visually update till moving the item in your inventory or relogging.
Follow me on twitter @charlotte_c_b for updates! You can also find me in irc.esper.net as Ilandria
Development of my mods is made possible by Full Effect Hosting
That's basically exactly how the vanilla method works
I implemented that and I'm having the exact same thing happen, where it changes behind-the-scenes but doesn't update the display until moving the items or relogging... I could post the entire class file here but it's getting a bit large at this point (like 350-400 lines) and I don't really want to make anyone read through everything. lol
I'll try to pick out just the functions that are related and post them all if you'd like, I really don't know what I'm doing wrong if this method works fine for you.
Follow me on twitter @charlotte_c_b for updates! You can also find me in irc.esper.net as Ilandria
Development of my mods is made possible by Full Effect Hosting
Oh the woes of learning to work with an API, lol :3
Follow me on twitter @charlotte_c_b for updates! You can also find me in irc.esper.net as Ilandria
Development of my mods is made possible by Full Effect Hosting