Jump to content

[SOLVED] is there a way to get stack.stackSize in 1.11 ?


trollworkout

Recommended Posts

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.

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.

Link to comment
Share on other sites

You'd have to look it the

ItemStack

class if there's a method for it.

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/

Link to comment
Share on other sites

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 ?

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.

Link to comment
Share on other sites

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.

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.

Link to comment
Share on other sites

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):

 

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

 

Link to comment
Share on other sites

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):

 

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.

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.

Link to comment
Share on other sites

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):

 

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.

width=233 height=253

tzIrzEf.jpg?1 [/img]

Link to comment
Share on other sites

Thanks Choonster I am testing this right now. It appears to be correct.

 

First boot of 1.11

Ob3jnZf.png

 

:D

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.

Link to comment
Share on other sites

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?

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.

Link to comment
Share on other sites

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.

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.

Link to comment
Share on other sites

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;

        }

Link to comment
Share on other sites

Thanks Choonster !

 

 

but it was so beautiful....

if (!playerIn.capabilities.isCreativeMode)

        {

            --itemStackIn.stackSize;

        }

 

nah dude but you can still -- tho

func_190918_g(1)

 

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.

Link to comment
Share on other sites

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.

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.

Link to comment
Share on other sites

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.

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/

Link to comment
Share on other sites

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 :D anyway back 2 coding.

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.

Link to comment
Share on other sites

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 :D 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..

Link to comment
Share on other sites

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.

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.

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.