Posted December 17, 201311 yr Hello, In fact i have 2 weapons magazine in my inventory and each one has it s own number of ammo inside (ex: one has 3 and the other has 5) but it's the same item, number of ammo is a rand in the constructor. When i press a key i would like my weapon consumes one of magazine item but first taking the variable number of ammo inside it but i don't know how to acceed this value (to know wich one the weapon magazine the game will consume). The 2 weapons magazines are not stackable. Is there a solution? Thanks
December 17, 201311 yr Hi Yes there is, you have two choices that spring to mind (1) use the "damage value" to store the amount of ammo, or (2) use the NBT data to store the amount of ammo - setTagCompound, getTagCompound -TGG
December 17, 201311 yr Author Thanks for your reply. I've setted this.setMaxDamage(this.maxBullet); in constructor but when want to set the actual damage value (number of bullet who is randomly choosen) it ask for an itemstack but i don't have one in constructor. How can i set damage in constructor ?(Will be only used for display) public ItemMagazine(int id, int par2maxbullet) { super(id); this.maxStackSize = 1; this.maxBullet = par2maxbullet; this.bullet = itemRand.nextInt(this.maxBullet - 1) + 1; this.setMaxDamage(this.maxBullet); setCreativeTab(CreativeTabs.tabCombat); } And even if i can set damage, how can i get it in my ItemGun? (imagine i have 2 differents magazines) Thanks!
December 18, 201311 yr You don't set CURRENT damage in the constructor. The Item class is a singleton, only one of them exists at a time.* Each stack of your Item class is where the current damage comes in. You'd need to look through the player's inventory for those. *Exceptions exist. Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable. If you think this is the case, JUST REPORT ME. Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice. Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked. DO NOT PM ME WITH PROBLEMS. No help will be given.
December 18, 201311 yr Author I don't get it. In this; @SideOnly(Side.CLIENT) public void reloadingWeapon(Entity player, ItemStack itemStack) { if(player instanceof EntityPlayer) { //System.out.println("ReloadingWeapon"); if(((EntityPlayer)player).inventory.hasItem(this.bulletID)) { ((EntityPlayer)player).inventory.consumeInventoryItem(this.bulletID); } } } How can i look for the actual damage of the item (which is the actual number of bullet in the magazine) before consume it?
December 18, 201311 yr You need to look at the item stack damages. "Consume" just makes the stack size go down by 1. Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable. If you think this is the case, JUST REPORT ME. Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice. Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked. DO NOT PM ME WITH PROBLEMS. No help will be given.
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.