Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

Hey !

 

Recently I've make an item that can store mobs ( a Pokeball actually ) which can be fired with a kind of rocket pokelauncher.

 

I've some problems in here to differentiate my Pokeballs ( Empty or Not )

 

I find something to differentiate them at the end when it gets consummed :

 

            playerIn.inventory.clearMatchingItems(IFItems.Pokeball, 1, 1, null);

 

But I can't find anything like that to differentiate the 2 pokeballs in my rocket pokelauncher.

 

Code of the rocket pokelauncher :

 

 

public void onPlayerStoppedUsing(ItemStack stack, World worldIn, EntityPlayer playerIn, int timeLeft)

    {    

    boolean item = playerIn.inventory.hasItem(IFItems.Pokeball);

        boolean crea = playerIn.capabilities.isCreativeMode || EnchantmentHelper.getEnchantmentLevel(Enchantment.infinity.effectId, stack) > 0;

       

        if (item || crea) {

 

        int i = this.getMaxItemUseDuration(stack) - timeLeft;

            net.minecraftforge.event.entity.player.ArrowLooseEvent event = new net.minecraftforge.event.entity.player.ArrowLooseEvent(playerIn, stack, i);

            if (net.minecraftforge.common.MinecraftForge.EVENT_BUS.post(event)) return;

            i = event.charge;

            float f = (float)i / 20.0F;

            f = (f * f + f * 2.0F) / 3.0F;

 

            if ((double)f < 0.1D)

            {

                return;

            }

 

            if (f > 1.0F)

            {

                f = 1.0F;

            }

       

            EntityPokeball entitypb = new EntityPokeball(worldIn, playerIn, f * 2.0F);

 

            worldIn.playSoundAtEntity(playerIn, "random.bow", 1.0F, 1.0F / (itemRand.nextFloat() * 0.4F + 1.2F) + f * 0.5F);

 

            if (crea)

            {

            entitypb.canBePickedUp = 0;

            }

            else

            {

                               

                playerIn.inventory.clearMatchingItems(IFItems.Pokeball, 1, 1, null);

           

            }

            if (!worldIn.isRemote)

            {

                worldIn.spawnEntityInWorld(entitypb);

            }

            }

}

 

 

 

Thanks for your help in advance.

"But I can't find anything like that to differentiate the 2 pokeballs in my rocket pokelauncher."

 

I don't quite understand?

 

ItemStack is ItemStack, if you have its instance you can "differentiate" it anywhere. #clearMatchingItems is an utility method, if you can't use it where you want to use it - simply write your own...

1.7.10 is no longer supported by forge, you are on your own.

  • Author

Sorry for my stupid question.

 

Thanks for your answer.

 

I did this and it's working so

 

playerIn.inventory.hasItemStack(new ItemStack(IFItems.Pokeball, 1/*amout*/, 1/*metadata*/));

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

Important Information

By using this site, you agree to our Terms of Use.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.