trollworkout Posted November 17, 2016 Posted November 17, 2016 I need to know how many items of one type I got in a stack but seems stackSize is no longer public or it has changed for 1.11 ? My code logic depends on counting the amount of items of one type. Quote Disclaimer: I been told to keep my opinions to myself, to shut up and that I am spreading lies and misinformation or even that my methods are unorthodox and or too irregular. Here are my suggestions take it or leave it.
larsgerrits Posted November 17, 2016 Posted November 17, 2016 You'd have to look it the ItemStack class if there's a method for it. Quote Don't PM me with questions. They will be ignored! Make a thread on the appropriate board for support. 1.12 -> 1.13 primer by williewillus. 1.7.10 and older versions of Minecraft are no longer supported due to it's age! Update to the latest version for support. http://www.howoldisminecraft1710.today/
gurujive Posted November 17, 2016 Posted November 17, 2016 On 11/17/2016 at 1:13 AM, larsgerrits said: You'd have to look it the ItemStack class if there's a method for it. ItemStack is not visible. Quote
trollworkout Posted November 17, 2016 Author Posted November 17, 2016 Nope I just had a look and it seems stackSize got made private . The only possible way to get it now is just as part of toString() Is this intentional or an accident? Will we ever have a getter for stackSize ? Quote Disclaimer: I been told to keep my opinions to myself, to shut up and that I am spreading lies and misinformation or even that my methods are unorthodox and or too irregular. Here are my suggestions take it or leave it.
Choonster Posted November 17, 2016 Posted November 17, 2016 ItemStack#func_190916_E returns the stack size if the stack is valid (see ItemStack#func_190926_b , which returns true if the stack is invalid/empty) or 0 if it's not. Quote Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.
gurujive Posted November 17, 2016 Posted November 17, 2016 On 11/17/2016 at 1:25 AM, Choonster said: ItemStack#func_190916_E returns the stack size if the stack is valid (see ItemStack#func_190926_b , which returns true if the stack is invalid/empty) or 0 if it's not. This isn't working for me, and I have no code errors (and I went back through and changed the entities accordingly to 1.11) (I can share src if need be): Reveal hidden contents public class ItemSphere extends Item { public ItemSphere() { this.maxStackSize = 16; this.setCreativeTab(ModCreativeTabs.example_tab); } public ActionResult<ItemStack> onItemRightClick(World itemStackIn, EntityPlayer worldIn, EnumHand playerIn) { ItemStack itemstack = worldIn.getHeldItem(playerIn); if (!worldIn.capabilities.isCreativeMode) { itemstack.func_190918_g(1); } itemStackIn.playSound((EntityPlayer)null, worldIn.posX, worldIn.posY, worldIn.posZ, SoundEvents.ENTITY_SNOWBALL_THROW, SoundCategory.NEUTRAL, 0.5F, 0.4F / (itemRand.nextFloat() * 0.4F + 0.8F)); if (!itemStackIn.isRemote) { EntitySphere entitythrowable = new EntitySphere(itemStackIn, worldIn); entitythrowable.setHeadingFromThrower(worldIn, worldIn.rotationPitch, worldIn.rotationYaw, 0.0F, 1.5F, 1.0F); itemStackIn.spawnEntityInWorld(entitythrowable); } worldIn.addStat(StatList.getObjectUseStats(this)); return new ActionResult(EnumActionResult.SUCCESS, itemstack); } } Quote
Choonster Posted November 17, 2016 Posted November 17, 2016 On 11/17/2016 at 1:28 AM, gurujive said: Quote ItemStack#func_190916_E returns the stack size if the stack is valid (see ItemStack#func_190926_b , which returns true if the stack is invalid/empty) or 0 if it's not. This isn't working for me, and I have no code errors (and I went back through and changed the entities accordingly to 1.11) (I can share src if need be): Reveal hidden contents public class ItemSphere extends Item { public ItemSphere() { this.maxStackSize = 16; this.setCreativeTab(ModCreativeTabs.example_tab); } public ActionResult<ItemStack> onItemRightClick(World itemStackIn, EntityPlayer worldIn, EnumHand playerIn) { ItemStack itemstack = worldIn.getHeldItem(playerIn); if (!worldIn.capabilities.isCreativeMode) { itemstack.func_190918_g(1); } itemStackIn.playSound((EntityPlayer)null, worldIn.posX, worldIn.posY, worldIn.posZ, SoundEvents.ENTITY_SNOWBALL_THROW, SoundCategory.NEUTRAL, 0.5F, 0.4F / (itemRand.nextFloat() * 0.4F + 0.8F)); if (!itemStackIn.isRemote) { EntitySphere entitythrowable = new EntitySphere(itemStackIn, worldIn); entitythrowable.setHeadingFromThrower(worldIn, worldIn.rotationPitch, worldIn.rotationYaw, 0.0F, 1.5F, 1.0F); itemStackIn.spawnEntityInWorld(entitythrowable); } worldIn.addStat(StatList.getObjectUseStats(this)); return new ActionResult(EnumActionResult.SUCCESS, itemstack); } } What exactly isn't working? Forge hasn't yet added the ability to register entities in 1.11, so it's unlikely that any modded entity will work. Quote Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.
gurujive Posted November 17, 2016 Posted November 17, 2016 On 11/17/2016 at 1:47 AM, Choonster said: Quote Quote ItemStack#func_190916_E returns the stack size if the stack is valid (see ItemStack#func_190926_b , which returns true if the stack is invalid/empty) or 0 if it's not. This isn't working for me, and I have no code errors (and I went back through and changed the entities accordingly to 1.11) (I can share src if need be): Reveal hidden contents public class ItemSphere extends Item { public ItemSphere() { this.maxStackSize = 16; this.setCreativeTab(ModCreativeTabs.example_tab); } public ActionResult<ItemStack> onItemRightClick(World itemStackIn, EntityPlayer worldIn, EnumHand playerIn) { ItemStack itemstack = worldIn.getHeldItem(playerIn); if (!worldIn.capabilities.isCreativeMode) { itemstack.func_190918_g(1); } itemStackIn.playSound((EntityPlayer)null, worldIn.posX, worldIn.posY, worldIn.posZ, SoundEvents.ENTITY_SNOWBALL_THROW, SoundCategory.NEUTRAL, 0.5F, 0.4F / (itemRand.nextFloat() * 0.4F + 0.8F)); if (!itemStackIn.isRemote) { EntitySphere entitythrowable = new EntitySphere(itemStackIn, worldIn); entitythrowable.setHeadingFromThrower(worldIn, worldIn.rotationPitch, worldIn.rotationYaw, 0.0F, 1.5F, 1.0F); itemStackIn.spawnEntityInWorld(entitythrowable); } worldIn.addStat(StatList.getObjectUseStats(this)); return new ActionResult(EnumActionResult.SUCCESS, itemstack); } } What exactly isn't working? Forge hasn't yet added the ability to register entities in 1.11, so it's unlikely that any modded entity will work. With the changes when you right click it wont render the entity, but the entity will act as an entity and does exist. The item will drop and is visible in hand. So that sounds about right, I do believe. [/img] Quote
trollworkout Posted November 17, 2016 Author Posted November 17, 2016 Thanks Choonster I am testing this right now. It appears to be correct. First boot of 1.11 Quote Disclaimer: I been told to keep my opinions to myself, to shut up and that I am spreading lies and misinformation or even that my methods are unorthodox and or too irregular. Here are my suggestions take it or leave it.
gurujive Posted November 17, 2016 Posted November 17, 2016 I'm totally stoked man I can hardly wait.... magical llamas :] skeleton wizards >-|o|> Quote
trollworkout Posted November 17, 2016 Author Posted November 17, 2016 Wait so that means func_190916_E returns 0 if the stack is invalid? ie it uses the _b one to check if stack is valid and if the _b returns 0 it will also return 0 which is now AIR . Seems Mojang is trying to get rid of null for some reason. So I am wondering if I can now use _E for null check AND stack size AT THE SAME TIME no longer need to use stack != null && stack.func_190916_E > 10 just saying if func_190916_E > 10 is automatically valid ie not null? Quote Disclaimer: I been told to keep my opinions to myself, to shut up and that I am spreading lies and misinformation or even that my methods are unorthodox and or too irregular. Here are my suggestions take it or leave it.
Choonster Posted November 17, 2016 Posted November 17, 2016 Yes, ItemStack s are no loner allowed to be null , the default value is now ItemStack#field_190927_a (the empty/invalid ItemStack ). ItemStack#func_190916_E checks the validity of the ItemStack for you, so you don't have to check it yourself. Quote Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.
gurujive Posted November 17, 2016 Posted November 17, 2016 On 11/17/2016 at 3:31 AM, Choonster said: Yes, ItemStack s are no loner allowed to be null , the default value is now ItemStack#field_190927_a (the empty/invalid ItemStack ). ItemStack#func_190916_E checks the validity of the ItemStack for you, so you don't have to check it yourself. but it was so beautiful.... if (!playerIn.capabilities.isCreativeMode) { --itemStackIn.stackSize; } Quote
trollworkout Posted November 17, 2016 Author Posted November 17, 2016 Thanks Choonster ! On 11/17/2016 at 3:37 AM, gurujive said: but it was so beautiful.... if (!playerIn.capabilities.isCreativeMode) { --itemStackIn.stackSize; } nah dude but you can still -- tho func_190918_g(1) Quote Disclaimer: I been told to keep my opinions to myself, to shut up and that I am spreading lies and misinformation or even that my methods are unorthodox and or too irregular. Here are my suggestions take it or leave it.
Choonster Posted November 17, 2016 Posted November 17, 2016 On 11/17/2016 at 3:37 AM, gurujive said: Quote Yes, ItemStack s are no loner allowed to be null , the default value is now ItemStack#field_190927_a (the empty/invalid ItemStack ). ItemStack#func_190916_E checks the validity of the ItemStack for you, so you don't have to check it yourself. but it was so beautiful.... if (!playerIn.capabilities.isCreativeMode) { --itemStackIn.stackSize; } ItemStack#func_190918_g decrements the stack size by the specified amount. Quote Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.
larsgerrits Posted November 17, 2016 Posted November 17, 2016 On 11/17/2016 at 3:37 AM, gurujive said: Quote Yes, ItemStack s are no loner allowed to be null , the default value is now ItemStack#field_190927_a (the empty/invalid ItemStack ). ItemStack#func_190916_E checks the validity of the ItemStack for you, so you don't have to check it yourself. but it was so beautiful.... if (!playerIn.capabilities.isCreativeMode) { --itemStackIn.stackSize; } ItemStack#func_190918_g( amount ) will remove amount from the stacksize. Quote Don't PM me with questions. They will be ignored! Make a thread on the appropriate board for support. 1.12 -> 1.13 primer by williewillus. 1.7.10 and older versions of Minecraft are no longer supported due to it's age! Update to the latest version for support. http://www.howoldisminecraft1710.today/
trollworkout Posted November 17, 2016 Author Posted November 17, 2016 this is unintentional but pretty sure you can add to stack size like func_190918_g(-1) by using the decrement function hahaha mojang probably made 2 functions add and sub but you only really need one to change the amount anyway back 2 coding. Quote Disclaimer: I been told to keep my opinions to myself, to shut up and that I am spreading lies and misinformation or even that my methods are unorthodox and or too irregular. Here are my suggestions take it or leave it.
gurujive Posted November 17, 2016 Posted November 17, 2016 On 11/17/2016 at 3:25 PM, diesieben07 said: Quote this is unintentional but pretty sure you can add to stack size like func_190918_g(-1) by using the decrement function hahaha mojang probably made 2 functions add and sub but you only really need one to change the amount anyway back 2 coding. Yes, the decrement method is actually just an alias that uses the increment method. This is just for aesthetics, because stack.increment(-1) looks weird. When did you get 26,000 somethin' posts? I'm pretty certain that takes about 20 years. (There's no way) Edit: ok, so about 4 years.. Quote
Draco18s Posted November 17, 2016 Posted November 17, 2016 On 11/17/2016 at 6:37 PM, gurujive said: When did you get 26,000 somethin' posts? I'm pretty certain that takes about 20 years. (There's no way) 16.4 posts per day is not that many, especially for a moderator. Quote 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.
gurujive Posted November 17, 2016 Posted November 17, 2016 On 11/17/2016 at 6:39 PM, diesieben07 said: More like 4 years. Well, you're doin' a good job. Keep it up Quote
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.