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

I have subscribed to the ServerChatEvent and am searching the inventory for an item but the entire inventory appears to be empty. I can provide code if necessary but do not see how my code could have created this problem (for testing all I'm doing is looping through the inventory and printing to the console if an itemstack position is not null).

 

Thanks in advance

I would recommend posting your code, you may have made a mistake somewhere without realising it.

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.

  • Author

You're probably right, just didn't want to have to load another browser.

 

Event Handler

public class SCEventHandler
{

    @SubscribeEvent
    public void HandleServerChat(ServerChatEvent event)
    {
        System.out.println("Running HandleServerChat");
        ItemStack[] inventory = event.player.getInventory();
        System.out.println(inventory);
        boolean hasMufflingCrystal = false;
        for (int i = 0; i < inventory.length; i++)
        {
            ItemStack item = inventory[i];
            if (item != null )//&& item.getItem() instanceof ItemCrystal && item.getItemDamage() == SCNames.Items.CRYSTAL.length - 1)
            {
                System.out.println("item exists");
                hasMufflingCrystal = true;
            }
            if (hasMufflingCrystal)
                break;
        }
        if (hasMufflingCrystal)
        {
            System.out.println("Cancelling event");
            event.setCanceled(true);
        }
    }
}

 

Mod Class (part)

    @EventHandler
    public void preInit(FMLPreInitializationEvent event)
    {
        MinecraftForge.EVENT_BUS.register(new SCEventHandler());

        SCItems.initItems();
        SCBlocks.initBlocks();
        SCTileEntities.initTileEntities();

        if(event.getSide() == Side.CLIENT)
        {
            SCItems.initTextures();
        }
    }

If you look at the implementation of

EntityPlayer#getInventory

, you'll see that it actually returns the player's armour inventory rather than their main inventory. Use

EntityPlayer#inventory

or

PlayerMainInvWrapper

.

 

In 1.9.4+, call

ICapabilityProvider#getCapability

on an

EntityPlayer

with

CapabilityItemHandler.ITEM_HANDLER_CAPABILITY

and a vertical

EnumFacing

to get an

IItemHandler

wrapper of their main inventory or a

null

EnumFacing

to get an

IItemHandler

wrapper of their whole inventory (main, armour and off hand).

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.

Oh, my fault for expecting names to make sense. Thanks.

 

If it's any consolation, the method doesn't exist in 1.9+.

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.

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.