Jump to content

Recommended Posts

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

Posted

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.

Posted

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

Posted

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.

Posted

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

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